-<%
- my( $agentnum, %opt ) = @_;
+% if ( scalar(@agents) == 1 ) {
- my @agents;
- if ( $opt{'agents'} ) {
- @agents = @{ $opt{'agents'} };
- } else {
- @agents = qsearch( 'agent', { disabled=>'' } );
- }
+ <INPUT TYPE="hidden" NAME="<% $opt{'field'} || 'agentnum' %>" VALUE="<% $agents[0]->agentnum %>">
-%>
-
-<% if ( scalar(@agents) == 1 ) { %>
-
- <INPUT TYPE="hidden" NAME="agentnum" VALUE="<%= $agents[0]->agentnum %>">
-
-<% } else { %>
+% } else {
<TR>
- <TD ALIGN="right"><%= $opt{'label'} || 'Agent: ' %></TD>
+ <TD ALIGN="right"><% $opt{'label'} || 'Agent' %></TD>
<TD>
- <%= include( '/elements/select-agent.html', $agentnum,
- 'agents' => \@agents,
+ <% include( '/elements/select-agent.html',
+ 'curr_value' => $agentnum,
+ 'agents' => \@agents,
+ %opt,
)
%>
</TD>
</TR>
-<% } %>
+% }
+
+<%init>
+
+my %opt = @_;
+my $agentnum = $opt{'curr_value'} || $opt{'value'};
+
+my @agents;
+if ( $opt{'agents'} ) {
+ #@agents = @{ $opt{'agents'} };
+ #here is the agent virtualization
+ my $agentnums_href = $FS::CurrentUser::CurrentUser->agentnums_href;
+ @agents = grep $agentnums_href->{$_->agentnum}, @{ $opt{'agents'} };
+ delete $opt{'agents'};
+} else {
+ @agents = $FS::CurrentUser::CurrentUser->agents;
+}
+
+</%init>