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