v4 style
[freeside.git] / httemplate / elements / select-agent.html
index c2a5e4b..2bd0095 100644 (file)
@@ -1,24 +1,31 @@
-<%
-  my( $agentnum, %opt ) = @_;
-
-  my @agents;
-  if ( $opt{'agents'} ) {
-    @agents = @{ $opt{'agents'} };
+<& /elements/select-table.html,
+                 'table'         => 'agent',
+                 'name_col'      => 'agent',
+                 'value'         => $agentnum || '',
+                 'agent_virt'    => 1,
+                 'empty_label'   => $empty_label,
+                 'hashref'       => { 'disabled' => '' },
+                 'order_by'      => ' ORDER BY agent',
+                 'disable_empty' => $disable_empty,
+                 %opt,
+&>
+<%init>
+
+my %opt = @_;
+my $agentnum = $opt{'curr_value'} || $opt{'value'};
+
+$opt{'records'} = delete $opt{'agents'}
+  if $opt{'agents'};
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $empty_label = $opt{'empty_label'} ? $opt{'empty_label'} : 'all';
+my $disable_empty = 0;
+if ( $opt{'agent_null_right'} ) {
+  if ( $curuser->access_right($opt{'agent_null_right'}) ) {
+    $disable_empty = 0;
   } else {
-    @agents = qsearch( 'agent', { disabled=>'' } );
+    $disable_empty = 1;
   }
+}
 
-%>
-
-<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 %>
-
-  <% } %>
-
-</SELECT>
-
+</%init>