adding new elements: percentage input, fixed country and state display, tablebreak...
[freeside.git] / httemplate / elements / select-agent.html
index c2a5e4b..54069a5 100644 (file)
@@ -1,24 +1,21 @@
-<%
-  my( $agentnum, %opt ) = @_;
-
-  my @agents;
-  if ( $opt{'agents'} ) {
-    @agents = @{ $opt{'agents'} };
-  } else {
-    @agents = qsearch( 'agent', { disabled=>'' } );
-  }
-
+<% include( '/elements/select-table.html',
+                 'table'       => 'agent',
+                 'name_col'    => 'agent',
+                 'value'       => $agentnum || '',
+                 'empty_label' => 'all',
+                 'hashref'     => { 'disabled' => '' },
+                 'extra_sql'   => ' AND '.
+                                  $FS::CurrentUser::CurrentUser->agentnums_sql.
+                                  ' ORDER BY agent',
+                 %opt,
+             )
 %>
+<%init>
 
-<SELECT NAME="agentnum">
-
-  <OPTION VALUE="">all</OPTION>
-
-  <% foreach my $agent ( sort { $a->agent cmp $b->agent } @agents ) { %>
-
-    <OPTION VALUE="<%= $agent->agentnum %>"<%= $agentnum == $agent->agentnum ? ' SELECTED' : '' %>><%= $agent->agent %>
-
-  <% } %>
+my %opt = @_;
+my $agentnum = $opt{'curr_value'} || $opt{'value'};
 
-</SELECT>
+$opt{'records'} = delete $opt{'agents'}
+  if $opt{'agents'};
 
+</%init>