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