add ability to edit the agent overrides from the main config, RT#4218
authorivan <ivan>
Fri, 1 May 2009 01:07:45 +0000 (01:07 +0000)
committerivan <ivan>
Fri, 1 May 2009 01:07:45 +0000 (01:07 +0000)
httemplate/config/config-process.cgi
httemplate/config/config-view.cgi

index 894dc41..a5918c0 100644 (file)
@@ -65,7 +65,7 @@ $conf->delete($_, $agentnum) foreach @delete;
   <SCRIPT TYPE="text/javascript">
 %   my $n = 0;
 %   foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
-    var configCell = window.top.document.getElementById('<% $i->key. $n %>');
+    var configCell = window.top.document.getElementById('<% $agentnum. $i->key. $n %>');
     //alert('found cell ' + configCell);
 %     if (    $type eq 'textarea'
 %          || $type eq 'editlist'
index 41ecfd2..534de02 100644 (file)
@@ -3,6 +3,21 @@
 Click on a configuration value to change it.
 <BR><BR>
 
+% unless ( $page_agent ) {
+%
+%   if ( $cgi->param('showagent') ) {
+%     $cgi->param('showagent', 0);
+      ( <a href="<% $cgi->self_url %>">hide agent overrides</a> )
+%     $cgi->param('showagent', 1);
+%   } else {
+%     $cgi->param('showagent', 1);
+      ( <a href="<% $cgi->self_url %>">show agent overrides</a> )
+%     $cgi->param('showagent', 0);
+%   }
+%
+% }
+<BR><BR>
+
 <% include('/elements/init_overlib.html') %>
 
 % if ($FS::UID::use_confcompat) {
@@ -42,6 +57,26 @@ Click on a configuration value to change it.
 %     #$width =
 %     #$height = 
 %   }
+%
+%   my @agents = ();
+%   if ( $page_agent ) {
+%     @agents = ( $page_agent );
+%   } else {
+%     @agents = (
+%       '',
+%       grep { defined( _config_agentonly($conf, $i->key, $_->agentnum) ) }
+%            @all_agents
+%     );
+%   }
+%
+%   foreach my $agent ( @agents ) {
+%     my $agentnum = $agent ? $agent->agentnum : '';
+%
+%     my $label = $i->key;
+%     $label = '['. $agent->agent. "] $label"
+%       if $agent && $cgi->param('showagent');
+%
+%     #indentation :/
 
     <tr>
       <td><% include('/elements/popup_link.html',
@@ -50,8 +85,9 @@ Click on a configuration value to change it.
                        'width'       => $width,
                        'height'      => $height,
                        'actionlabel' => 'Enter configuration value',
-                       'label'       => '<b>'. $i->key. '</b>',
-                       'aname'       => $i->key,
+                       'label'       => "<b>$label</b>",
+                       'aname'       => $i->key, #agentnum
+                                                 # if $cgi->param('showagent')?
                     )
           %>: <% $i->description %>
       </td>
@@ -102,21 +138,19 @@ Click on a configuration value to change it.
 %             || $type eq 'selectmultiple' ) { 
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
-<font size="-2"><pre>
-<% encode_entities(join("\n",
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
+<font size="-2"><pre><% encode_entities(join("\n",
      map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
          $conf->config($i->key, $agentnum)
    ) )
-%>
-</pre></font>
+%></pre></font>
               </td>
             </tr>
 
 %   } elsif ( $type eq 'checkbox' ) {
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
             </tr>
 
 %   } elsif ( $type eq 'select' && $i->select_hash ) {
@@ -129,7 +163,7 @@ Click on a configuration value to change it.
 %     }
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
               </td>
             </tr>
@@ -137,7 +171,7 @@ Click on a configuration value to change it.
 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
               </td>
             </tr>
@@ -145,7 +179,7 @@ Click on a configuration value to change it.
 %   } elsif ( $type eq 'select-sub' ) { 
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
                 <% $conf->config($i->key, $agentnum) %>: 
                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
               </td>
@@ -162,35 +196,50 @@ Click on a configuration value to change it.
 
       </table></td>
     </tr>
-% } 
+
+% } # foreach my $agentnum
+
+% } # foreach my $i
 
   </table><br><br>
-% } 
 
+% } # foreach my $nav_section
 
 </body></html>
+<%once>
+
+#should probably be a Conf method.  what else would need to use it?
+sub _config_agentonly {
+  my($self,$name,$agentnum)=@_;
+  my $hashref = { 'name' => $name };
+  $hashref->{agentnum} = $agentnum;
+  local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
+  FS::Record::qsearchs('conf', $hashref);
+}
+
+</%once>
 <%init>
 
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
-my $agentnum = '';
+my $page_agent = '';
 my $title;
 my @menubar = ();
 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
-  $agentnum = $1;
-  my $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
-  die "Agent $agentnum not found!" unless $agent;
+  my $page_agentnum = $1;
+  $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
+  die "Agent $page_agentnum not found!" unless $page_agent;
 
   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
-  $title = 'Agent Configuration for '. $agent->agent;
+  $title = 'Agent Configuration for '. $page_agent->agent;
 } else {
   $title = 'Global Configuration';
 }
 
 my $conf = new FS::Conf;
  
-my @config_items = grep { $agentnum ? $_->per_agent : 1 }
+my @config_items = grep { $page_agent ? $_->per_agent : 1 }
                    grep { $_->key != ~/^invoice_(html|latex|template)/ }
                         $conf->config_items; 
 
@@ -204,4 +253,10 @@ foreach my $section (@sections) {
 
 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
 
+my @all_agents = ();
+if ( $cgi->param('showagent') ) {
+  @all_agents = qsearch('agent', { 'disabled' => '' } );
+}
+warn 'all agents: '. join('-', @all_agents);
+
 </%init>