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