(start of) reconcile breakage from stale accounts, RT#6407
[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 %     my @keys = $conf->config($i->key, $agentnum);
214
215             <tr>
216               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
217                 <% join('<BR>', map { $_ # ': '. $svc, $pkg, whatever
218                                     }
219                                     @keys
220                        )
221                 %>
222               </td>
223             </tr>
224
225 %   } else {
226
227             <tr><td>
228               <font color="#ff0000">unknown type <% $type %></font>
229             </td></tr>
230 %   }
231 %   $n++;
232 % } 
233
234       </table></td>
235     </tr>
236
237 % } # foreach my $agentnum
238
239 % if ( @add_agents ) {
240
241   <tr>
242     <td>
243       <FORM>
244       Add <b><% $i->key %></b> override for
245         <% include('/elements/select-agent.html',
246                      'agents'      => \@add_agents,
247                      'empty_label' => 'Select agent',
248                      'onchange'    => "agent_changed",
249                      'id'          => 'agent_'. $i->key,
250                   )
251         %>
252       agent
253
254 %     my $agent_el = "document.getElementById('agent_". $i->key. "')";
255       <INPUT TYPE    = "button"
256              VALUE   = "Add"
257              ID      = "add_<% $i->key %>"
258              DISABLED
259              onClick = "<%
260                include('/elements/popup_link_onclick.html',
261                          'action'      =>
262                            'config.cgi?key='.      $i->key.
263                            ";agentnum=' + ".
264                              "$agent_el.options[$agent_el.selectedIndex].value".
265                              " + '",
266                          'width'       => $width,
267                          'height'      => $height,
268                          'actionlabel' => 'Enter configuration value',
269                       )
270              %>"
271       >
272       </FORM>
273     </td>
274   </tr>
275
276 % } #if @add_agents
277
278 % } # foreach my $i
279
280   </table><br><br>
281
282 % } # foreach my $nav_section
283
284 <SCRIPT TYPE="text/javascript">
285
286   function agent_changed(what) {
287     var key = what.id.substring(6); // trim agent_
288     var button = document.getElementById('add_'+key);
289     if ( what.selectedIndex > 0 ) {
290       button.disabled = false;
291     } else {
292       button.disabled = true;
293     }
294   }
295
296   function areyousure(what, href) {
297     if ( confirm("Are you sure you want to " + what + "?") == true )
298       window.location.href = href;
299   }
300
301 </SCRIPT>
302
303 </body></html>
304 <%init>
305
306 die "access denied"
307   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
308
309 my $page_agent = '';
310 my $title;
311 my @menubar = ();
312 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
313   my $page_agentnum = $1;
314   $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
315   die "Agent $page_agentnum not found!" unless $page_agent;
316
317   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
318   $title = 'Agent Configuration for '. $page_agent->agent;
319 } else {
320   $title = 'Global Configuration';
321 }
322
323 my $conf = new FS::Conf;
324  
325 my @config_items = grep { $page_agent ? $_->per_agent : 1 }
326                    grep { $page_agent ? 1 : !$_->agentonly }
327                         $conf->config_items; 
328
329 my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress );
330 my %deleteable = map { $_ => 1 } @deleteable;
331
332 my @sections = qw(required billing username password UI session shell BIND );
333 push @sections, '', 'deprecated';
334
335 my %section_items = ();
336 foreach my $section (@sections) {
337   $section_items{$section} = [ grep $_->section eq $section, @config_items ];
338 }
339
340 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
341
342 my @all_agents = ();
343 if ( $cgi->param('showagent') ) {
344   @all_agents = qsearch('agent', { 'disabled' => '' } );
345 }
346 warn 'all agents: '. join('-', @all_agents);
347
348 </%init>