add deprecated config options back to Conf.pm to fix "unapplypayments" fails existent...
[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 %     next if $section eq 'deprecated' && ! $conf->exists($i->key, $agentnum);
82 %
83 %     my $label = $i->key;
84 %     $label = '['. $agent->agent. "] $label"
85 %       if $agent && $cgi->param('showagent');
86 %
87 %     #indentation :/
88
89     <tr>
90       <td><% include('/elements/popup_link.html',
91                        'action'      => 'config.cgi?key='.      $i->key.
92                                                   ';agentnum='. $agentnum,
93                        'width'       => $width,
94                        'height'      => $height,
95                        'actionlabel' => 'Enter configuration value',
96                        'label'       => "<b>$label</b>",
97                        'aname'       => $i->key, #agentnum
98                                                  # if $cgi->param('showagent')?
99                     )
100           %>: <% $i->description %>
101 %       if ( $agent && $cgi->param('showagent') ) {
102 %         my $confnum =
103 %           _config_agentonly($conf, $i->key, $agent->agentnum)->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 %             ? _config_agentonly($conf, $i->key, $agent->agentnum)->confnum
110 %             : $conf->_config( $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             <tr>
163               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
164 <font size="-2"><pre><% encode_entities(join("\n",
165      map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
166          $conf->config($i->key, $agentnum)
167    ) )
168 %></pre></font>
169               </td>
170             </tr>
171
172 %   } elsif ( $type eq 'checkbox' ) {
173
174             <tr>
175               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
176             </tr>
177
178 %   } elsif ( $type eq 'select' && $i->select_hash ) {
179 %
180 %     my %hash;
181 %     if ( ref($i->select_hash) eq 'ARRAY' ) {
182 %       tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
183 %     } else {
184 %       tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
185 %     }
186
187             <tr>
188               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
189                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
190               </td>
191             </tr>
192
193 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
194
195             <tr>
196               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
197                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
198               </td>
199             </tr>
200
201 %   } elsif ( $type eq 'select-sub' ) { 
202
203             <tr>
204               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
205                 <% $conf->config($i->key, $agentnum) %>: 
206                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
207               </td>
208             </tr>
209
210 %   } else { 
211
212             <tr><td>
213               <font color="#ff0000">unknown type <% $type %></font>
214             </td></tr>
215 %   } 
216 %   $n++;
217 % } 
218
219       </table></td>
220     </tr>
221
222 % } # foreach my $agentnum
223
224 % if ( @add_agents ) {
225
226   <tr>
227     <td>
228       <FORM>
229       Add <b><% $i->key %></b> override for
230         <% include('/elements/select-agent.html',
231                      'agents'      => \@add_agents,
232                      'empty_label' => 'Select agent',
233                      'onchange'    => "agent_changed",
234                      'id'          => 'agent_'. $i->key,
235                   )
236         %>
237       agent
238
239 %     my $agent_el = "document.getElementById('agent_". $i->key. "')";
240       <INPUT TYPE    = "button"
241              VALUE   = "Add"
242              ID      = "add_<% $i->key %>"
243              DISABLED
244              onClick = "<%
245                include('/elements/popup_link_onclick.html',
246                          'action'      =>
247                            'config.cgi?key='.      $i->key.
248                            ";agentnum=' + ".
249                              "$agent_el.options[$agent_el.selectedIndex].value".
250                              " + '",
251                          'width'       => $width,
252                          'height'      => $height,
253                          'actionlabel' => 'Enter configuration value',
254                       )
255              %>"
256       >
257       </FORM>
258     </td>
259   </tr>
260
261 % } #if @add_agents
262
263 % } # foreach my $i
264
265   </table><br><br>
266
267 % } # foreach my $nav_section
268
269 <SCRIPT TYPE="text/javascript">
270
271   function agent_changed(what) {
272     var key = what.id.substring(6); // trim agent_
273     var button = document.getElementById('add_'+key);
274     if ( what.selectedIndex > 0 ) {
275       button.disabled = false;
276     } else {
277       button.disabled = true;
278     }
279   }
280
281   function areyousure(what, href) {
282     if ( confirm("Are you sure you want to " + what + "?") == true )
283       window.location.href = href;
284   }
285
286 </SCRIPT>
287
288 </body></html>
289 <%once>
290
291 #should probably be a Conf method.  what else would need to use it?
292 sub _config_agentonly {
293   my($self,$name,$agentnum)=@_;
294   my $hashref = { 'name' => $name };
295   $hashref->{agentnum} = $agentnum;
296   local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
297   FS::Record::qsearchs('conf', $hashref);
298 }
299
300 </%once>
301 <%init>
302
303 die "access denied"
304   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
305
306 my $page_agent = '';
307 my $title;
308 my @menubar = ();
309 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
310   my $page_agentnum = $1;
311   $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
312   die "Agent $page_agentnum not found!" unless $page_agent;
313
314   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
315   $title = 'Agent Configuration for '. $page_agent->agent;
316 } else {
317   $title = 'Global Configuration';
318 }
319
320 my $conf = new FS::Conf;
321  
322 my @config_items = grep { $page_agent ? $_->per_agent : 1 }
323                         $conf->config_items; 
324
325 my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress );
326 my %deleteable = map { $_ => 1 } @deleteable;
327
328 my @sections = qw(required billing username password UI session shell BIND );
329 push @sections, '', 'deprecated';
330
331 my %section_items = ();
332 foreach my $section (@sections) {
333   $section_items{$section} = [ grep $_->section eq $section, @config_items ];
334 }
335
336 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
337
338 my @all_agents = ();
339 if ( $cgi->param('showagent') ) {
340   @all_agents = qsearch('agent', { 'disabled' => '' } );
341 }
342 warn 'all agents: '. join('-', @all_agents);
343
344 </%init>