<%= hidden_field_tag :direction, direction %>
<%= hidden_field_tag :sort, sort %>
<table class="sortable std_format_table">
  <thead>
    <th><%= sortable 'lastname' %></th>
    <th><%= sortable 'firstname' %></th>
    <th></th>
  </thead>
  <tbody>
  <% @users.each do |u| %>
  <tr>
    <td><%= link_to u.lastname, [:trainers, u] %></td>
    <td><%= u.firstname %></td>
    <td>
    <%= link_to 'Logs', [:trainers, u] %> | <%= link_to 'Send Message', new_message_path(:recipient_id=>u.id) %>
    <% if program_id && (g=u.goal_sheet_for(program_id)) %>
      | <%= link_to('Goal Sheet', g) %>
      <% else %>      
    <% end %>
      <% if (np=u.most_recent_nutrition_plan) %>
      | <%= link_to "Nutrition Plan", :controller => 'admin/nutrition_plans', :action => 'build_nutrition', :id => np.id, :user_id => u.id, :meal_plan_id => np.meal_plan_id, :supplement_plan_id => np.supplement_plan_id, :format => 'pdf' %>
      <% end %>

      </td>
  </tr>
  <% if program_id && !u.enrollment_for(program_id).try(:goals).blank?  %>
  <tr>
    <td />
    <td />
    <td>Goals: <%= u.enrollment_for(program_id).goals %></td>
  </tr>
  <% end %>
  <% end %>
  </tbody>
</table>
<p><%= will_paginate @users %></p>