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