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