This commit was generated by cvs2svn to compensate for changes in r11022,
[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 <BR><BR>
20
21 <% include('/elements/init_overlib.html') %>
22
23 % if ($FS::UID::use_confcompat) {
24   <FONT SIZE="+1" COLOR="#ff0000">CONFIGURATION NOT STORED IN DATABASE -- USING COMPATIBILITY MODE</FONT><BR><BR>
25 %}
26
27 % foreach my $section (@sections) {
28
29     <A NAME="<% $section || 'unclassified' %>"></A>
30     <FONT SIZE="-2">
31
32 %   foreach my $nav_section (@sections) {
33 %
34 %     if ( $section eq $nav_section ) { 
35         [<A NAME="not<% $nav_section || 'unclassified' %>" style="background-color: #cccccc"><% ucfirst($nav_section || 'unclassified') %></A>]
36 %     } else { 
37         [<A HREF="#<% $nav_section || 'unclassified' %>"><% ucfirst($nav_section || 'unclassified') %></A>]
38 %     } 
39 %
40 %   } 
41
42   </FONT><BR>
43   <TABLE BGCOLOR="#cccccc" BORDER=1 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR="#999999">
44   <tr>
45     <th colspan="2" bgcolor="#dcdcdc">
46       <% ucfirst($section || 'unclassified') %>
47 %     if ( $curuser->option('show_confitem_counts') ) {
48         (<% scalar( @{ $section_items{$section} } ) %> items)
49 %     }
50     </th>
51   </tr>
52 % foreach my $i (@{ $section_items{$section} }) { 
53 %   my @types = ref($i->type) ? @{$i->type} : ($i->type);
54 %#  my( $width, $height ) = ( 522, 336 );
55 %   my( $width, $height ) = ( 600, 336 );
56 %   if ( grep $_ eq 'textarea', @types ) {
57 %     #800x600
58 %     $width = 763;
59 %     $height = 408;
60 %     #1024x768
61 %     #$width =
62 %     #$height = 
63 %   }
64 %
65 %   my @agents = ();
66 %   my @add_agents = ();
67 %   if ( $page_agent ) {
68 %     @agents = ( $page_agent );
69 %   } else {
70 %     @agents = ( '' );
71 %     if ( $i->per_agent ) {
72 %       foreach my $agent (@all_agents) {
73 %         if ( defined($conf->conf( $i->key, $agent->agentnum, 1 ) ) ) {
74 %           push @agents, $agent;
75 %         } else {
76 %           push @add_agents, $agent;
77 %         }
78 %       }
79 %     }
80 %   }
81 %
82 %   foreach my $agent ( @agents ) {
83 %     my $agentnum = $agent ? $agent->agentnum : '';
84 %
85 %     next if $section eq 'deprecated' && ! $conf->exists($i->key, $agentnum);
86 %
87 %     my $label = $i->key;
88 %     $label = '['. $agent->agent. "] $label"
89 %       if $agent && $cgi->param('showagent');
90 %
91 %     #indentation :/
92
93     <tr>
94       <td><% include('/elements/popup_link.html',
95                        'action'      => 'config.cgi?key='.      $i->key.
96                                                   ';agentnum='. $agentnum,
97                        'width'       => $width,
98                        'height'      => $height,
99                        'actionlabel' => 'Enter configuration value',
100                        'label'       => "<b>$label</b>",
101                        'aname'       => $i->key, #agentnum
102                                                  # if $cgi->param('showagent')?
103                     )
104           %>: <% $i->description %>
105 %       if ( $agent && $cgi->param('showagent') ) {
106 %         my $confnum = $conf->conf( $i->key, $agent->agentnum, 1 )->confnum;
107           (<A HREF="javascript:areyousure('delete this agent override', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view_showagent')">delete agent override</A>)
108 %       } elsif ( $i->base_key
109 %                 || ( $deleteable{$i->key} && $conf->exists($i->key) ) ) {
110 %         my $confnum =
111 %           $agent
112 %             ? $conf->conf( $i->key, $agent->agentnum, 1 )->confnum
113 %             : $conf->conf( $i->key )->confnum;
114 %         my $showagent = $cgi->param('showagent') ? '_showagent' : '';
115           (<A HREF="javascript:areyousure('delete this configuration item', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view<%$showagent%>')">delete configuration item</A>)
116 %       }
117
118       </td>
119       <td><table border=0>
120
121 % my $n = 0;
122 % foreach my $type (@types) {
123
124 %   if ( $type eq '' ) { 
125
126             <tr>
127               <td><font color="#ff0000">no type</font></td>
128             </tr>
129
130 %   } elsif ( $type eq 'image' ) {
131
132             <tr>
133               <td bgcolor='#ffffff'>
134                 <% $conf->exists($i->key, $agentnum)
135                      ? '<img src="config-image.cgi?key='.      $i->key.
136                                                  ';agentnum='. $agentnum. '">'
137                      : 'empty'
138                 %>
139               </td>
140             </tr>
141             <tr>
142               <td>
143                 <% $conf->exists($i->key, $agentnum)
144                      ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>!
145                      : ''
146                 %>
147               </td>
148             </tr>
149
150 %   } elsif ( $type eq 'binary' ) {
151
152             <tr>
153               <td>
154                 <% $conf->exists($i->key, $agentnum)
155                      ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>!
156                      : 'empty'
157                 %>
158               </td>
159             </tr>
160
161 %   } elsif (    $type eq 'textarea'
162 %             || $type eq 'editlist'
163 %             || $type eq 'selectmultiple'
164 %           )
165 %   {
166
167             <tr>
168               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
169 <font size="-2"><pre><% encode_entities(join("\n",
170      map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
171          $conf->config($i->key, $agentnum)
172    ) )
173 %></pre></font>
174               </td>
175             </tr>
176
177 %   } elsif ( $type eq 'checkbox' ) {
178
179             <tr>
180               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
181             </tr>
182
183 %   } elsif ( $type eq 'select' && $i->select_hash ) {
184 %
185 %     my %hash;
186 %     if ( ref($i->select_hash) eq 'ARRAY' ) {
187 %       tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
188 %     } else {
189 %       tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
190 %     }
191
192             <tr>
193               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
194                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
195               </td>
196             </tr>
197
198 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
199
200             <tr>
201               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
202                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
203               </td>
204             </tr>
205
206 %   } elsif ( $type eq 'select-sub' ) {
207
208             <tr>
209               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
210                 <% $conf->config($i->key, $agentnum) %>: 
211                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
212               </td>
213             </tr>
214
215 %   } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class)$/ ) {
216 %
217 %     my $table = $1;
218 %     my $namecol = $namecol{$table};
219 %     my $pkey = dbdef->table($table)->primary_key;
220 %
221 %     my @keys = $conf->config($i->key, $agentnum);
222
223             <tr>
224               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
225                 <% join( '<BR>',
226                          map {
227                            my $key = $_;
228                            my $record = qsearchs($table, { $pkey => $key });
229                            $record ? "$key: ".$record->$namecol() : $key;
230                          } @keys
231                        )
232                 %>
233               </td>
234             </tr>
235
236 %   } else {
237
238             <tr><td>
239               <font color="#ff0000">unknown type <% $type %></font>
240             </td></tr>
241 %   }
242 %   $n++;
243 % } 
244
245       </table></td>
246     </tr>
247
248 % } # foreach my $agentnum
249
250 % if ( @add_agents ) {
251
252   <tr>
253     <td>
254       <FORM>
255       Add <b><% $i->key %></b> override for
256         <% include('/elements/select-agent.html',
257                      'agents'      => \@add_agents,
258                      'empty_label' => 'Select agent',
259                      'onchange'    => "agent_changed",
260                      'id'          => 'agent_'. $i->key,
261                   )
262         %>
263       agent
264
265 %     my $agent_el = "document.getElementById('agent_". $i->key. "')";
266       <INPUT TYPE    = "button"
267              VALUE   = "Add"
268              ID      = "add_<% $i->key %>"
269              DISABLED
270              onClick = "<%
271                include('/elements/popup_link_onclick.html',
272                          'action'      =>
273                            'config.cgi?key='.      $i->key.
274                            ";agentnum=' + ".
275                              "$agent_el.options[$agent_el.selectedIndex].value".
276                              " + '",
277                          'width'       => $width,
278                          'height'      => $height,
279                          'actionlabel' => 'Enter configuration value',
280                       )
281              %>"
282       >
283       </FORM>
284     </td>
285   </tr>
286
287 % } #if @add_agents
288
289 % } # foreach my $i
290
291   </table><br><br>
292
293 % } # foreach my $nav_section
294
295 <SCRIPT TYPE="text/javascript">
296
297   function agent_changed(what) {
298     var key = what.id.substring(6); // trim agent_
299     var button = document.getElementById('add_'+key);
300     if ( what.selectedIndex > 0 ) {
301       button.disabled = false;
302     } else {
303       button.disabled = true;
304     }
305   }
306
307   function areyousure(what, href) {
308     if ( confirm("Are you sure you want to " + what + "?") == true )
309       window.location.href = href;
310   }
311
312 </SCRIPT>
313
314 </body></html>
315 <%once>
316 #false laziness w/config-process.cgi
317 my %namecol = (
318   'part_svc'  => 'svc',
319   'part_pkg'  => 'pkg',
320   'pkg_class' => 'classname',
321 );
322 </%once>
323 <%init>
324
325 my $curuser = $FS::CurrentUser::CurrentUser;
326
327 die "access denied" unless $curuser->access_right('Configuration');
328
329 my $page_agent = '';
330 my $title;
331 my @menubar = ();
332 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
333   my $page_agentnum = $1;
334   $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
335   die "Agent $page_agentnum not found!" unless $page_agent;
336
337   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
338   $title = 'Agent Configuration for '. $page_agent->agent;
339 } else {
340   $title = 'Global Configuration';
341 }
342
343 my $conf = new FS::Conf;
344  
345 my @config_items = grep { $page_agent ? $_->per_agent : 1 }
346                    grep { $page_agent ? 1 : !$_->agentonly }
347                         $conf->config_items; 
348
349 my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress );
350 my %deleteable = map { $_ => 1 } @deleteable;
351
352 my @sections = qw(required billing invoicing notification UI self-service username password session shell BIND telephony );
353 push @sections, '', 'deprecated';
354
355 my %section_items = ();
356 foreach my $section (@sections) {
357   $section_items{$section} = [ grep $_->section eq $section, @config_items ];
358 }
359
360 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
361
362 my @all_agents = ();
363 if ( $cgi->param('showagent') ) {
364   @all_agents = qsearch('agent', { 'disabled' => '' } );
365 }
366
367 </%init>