add ability to edit the agent overrides from the main config, RT#4218
[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 %   if ( grep $_ eq 'textarea', @types ) {
53 %     #800x600
54 %     $width = 763;
55 %     $height = 408;
56 %     #1024x768
57 %     #$width =
58 %     #$height = 
59 %   }
60 %
61 %   my @agents = ();
62 %   if ( $page_agent ) {
63 %     @agents = ( $page_agent );
64 %   } else {
65 %     @agents = (
66 %       '',
67 %       grep { defined( _config_agentonly($conf, $i->key, $_->agentnum) ) }
68 %            @all_agents
69 %     );
70 %   }
71 %
72 %   foreach my $agent ( @agents ) {
73 %     my $agentnum = $agent ? $agent->agentnum : '';
74 %
75 %     my $label = $i->key;
76 %     $label = '['. $agent->agent. "] $label"
77 %       if $agent && $cgi->param('showagent');
78 %
79 %     #indentation :/
80
81     <tr>
82       <td><% include('/elements/popup_link.html',
83                        'action'      => 'config.cgi?key='.      $i->key.
84                                                   ';agentnum='. $agentnum,
85                        'width'       => $width,
86                        'height'      => $height,
87                        'actionlabel' => 'Enter configuration value',
88                        'label'       => "<b>$label</b>",
89                        'aname'       => $i->key, #agentnum
90                                                  # if $cgi->param('showagent')?
91                     )
92           %>: <% $i->description %>
93       </td>
94       <td><table border=0>
95
96 % my $n = 0;
97 % foreach my $type (@types) {
98
99 %   if ( $type eq '' ) { 
100
101             <tr>
102               <td><font color="#ff0000">no type</font></td>
103             </tr>
104
105 %   } elsif ( $type eq 'image' ) {
106
107             <tr>
108               <td bgcolor='#ffffff'>
109                 <% $conf->exists($i->key, $agentnum)
110                      ? '<img src="config-image.cgi?key='.      $i->key.
111                                                  ';agentnum='. $agentnum. '">'
112                      : 'empty'
113                 %>
114               </td>
115             </tr>
116             <tr>
117               <td>
118                 <% $conf->exists($i->key, $agentnum)
119                      ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>!
120                      : ''
121                 %>
122               </td>
123             </tr>
124
125 %   } elsif ( $type eq 'binary' ) {
126
127             <tr>
128               <td>
129                 <% $conf->exists($i->key, $agentnum)
130                      ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>!
131                      : 'empty'
132                 %>
133               </td>
134             </tr>
135
136 %   } elsif (    $type eq 'textarea'
137 %             || $type eq 'editlist'
138 %             || $type eq 'selectmultiple' ) { 
139
140             <tr>
141               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
142 <font size="-2"><pre><% encode_entities(join("\n",
143      map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
144          $conf->config($i->key, $agentnum)
145    ) )
146 %></pre></font>
147               </td>
148             </tr>
149
150 %   } elsif ( $type eq 'checkbox' ) {
151
152             <tr>
153               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
154             </tr>
155
156 %   } elsif ( $type eq 'select' && $i->select_hash ) {
157 %
158 %     my %hash;
159 %     if ( ref($i->select_hash) eq 'ARRAY' ) {
160 %       tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
161 %     } else {
162 %       tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
163 %     }
164
165             <tr>
166               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
167                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
168               </td>
169             </tr>
170
171 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
172
173             <tr>
174               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
175                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
176               </td>
177             </tr>
178
179 %   } elsif ( $type eq 'select-sub' ) { 
180
181             <tr>
182               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
183                 <% $conf->config($i->key, $agentnum) %>: 
184                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
185               </td>
186             </tr>
187
188 %   } else { 
189
190             <tr><td>
191               <font color="#ff0000">unknown type <% $type %></font>
192             </td></tr>
193 %   } 
194 %   $n++;
195 % } 
196
197       </table></td>
198     </tr>
199
200 % } # foreach my $agentnum
201
202 % } # foreach my $i
203
204   </table><br><br>
205
206 % } # foreach my $nav_section
207
208 </body></html>
209 <%once>
210
211 #should probably be a Conf method.  what else would need to use it?
212 sub _config_agentonly {
213   my($self,$name,$agentnum)=@_;
214   my $hashref = { 'name' => $name };
215   $hashref->{agentnum} = $agentnum;
216   local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
217   FS::Record::qsearchs('conf', $hashref);
218 }
219
220 </%once>
221 <%init>
222
223 die "access denied"
224   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
225
226 my $page_agent = '';
227 my $title;
228 my @menubar = ();
229 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
230   my $page_agentnum = $1;
231   $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
232   die "Agent $page_agentnum not found!" unless $page_agent;
233
234   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
235   $title = 'Agent Configuration for '. $page_agent->agent;
236 } else {
237   $title = 'Global Configuration';
238 }
239
240 my $conf = new FS::Conf;
241  
242 my @config_items = grep { $page_agent ? $_->per_agent : 1 }
243                    grep { $_->key != ~/^invoice_(html|latex|template)/ }
244                         $conf->config_items; 
245
246 my @sections = qw(required billing username password UI session shell BIND );
247 push @sections, '', 'deprecated';
248
249 my %section_items = ();
250 foreach my $section (@sections) {
251   $section_items{$section} = [ grep $_->section eq $section, @config_items ];
252 }
253
254 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
255
256 my @all_agents = ();
257 if ( $cgi->param('showagent') ) {
258   @all_agents = qsearch('agent', { 'disabled' => '' } );
259 }
260 warn 'all agents: '. join('-', @all_agents);
261
262 </%init>