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