<div class="mt10">
  <div class="homepagePostDeadline">
    迟交扣分：<%= activity.late_penalty%>分
  </div>
  <% if activity.anonymous_comment == 0%>
      <div class="homepagePostDeadline" style="float: right; margin-right: 220px;" id="evaluation_start_time_<%=user_activity_id %>">
        匿评开启时间：<%= activity.homework_detail_manual.evaluation_start%>&nbsp;00:00
      </div>
  <% end %>
</div>
<div class="cl"></div>
<div>
  <% if activity.anonymous_comment == 0%>
      <div class="homepagePostDeadline">
        缺评扣分：<%= activity.homework_detail_manual.absence_penalty%>分/作品
      </div>
  <% end %>
  <% if activity.anonymous_comment == 0%>
      <div class="homepagePostDeadline" style="float: right; margin-right: 220px;" id="evaluation_end_time_<%=user_activity_id %>">
        匿评关闭时间：<%= activity.homework_detail_manual.evaluation_end%>&nbsp;23:59
      </div>
  <% end %>
</div>
<div class="cl"></div>
<% if activity.student_works.has_committed.count != 0 %>
    <% sw = activity.student_works.has_committed.reorder("commit_time desc").first %>
    <div class="mt10 homepagePostDeadline">
      #&nbsp;<%=time_from_now sw.commit_time %><%= link_to sw.user.show_name, user_activities_path(sw.user_id), :class => "newsBlue ml5 mr5"%>提交了作品
    </div>
<% end %>
<div class="cl"></div>
<% if activity.student_works.count != 0 %>
    <% sw_id = "("+activity.student_works.map{|sw| sw.id}.join(",")+")" %>
    <%# student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %>
    <% student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc") %>
    <% unless student_work_scores.empty?  %>
        <% last_score = student_work_scores.first %>
        <div class="mt10">
          <p class="fontGrey2">#&nbsp;<%=time_from_now last_score.created_at %>
            <%= link_to last_score.user.show_name, user_activities_path(last_score.user_id), :class => "newsBlue ml5 mr5"%>评阅了作品，优秀排行：
          </p>
        </div>
    <% end %>
    <div>
      <% if activity.homework_type != 2 %>
          <% ids = student_work_scores.empty? ? "(-1)" : '('+student_work_scores.map{|sw|sw.student_work_id}.join(',')+')' %>
          <% student_works = activity.student_works.has_committed.select("student_works.*,student_works.work_score as score").where("student_works.id in #{ids}").order("score desc") %>
      <% else %>
          <% student_works = activity.student_works.has_committed.select("student_works.*,student_works.work_score as score").order("score desc") %>
      <% end %>
      <% student_works.includes(:user).each_with_index do |sw, i| %>
          <div class="fl mr10 w100" style="text-align:center;">
            <a href="javascript:void(0);" class="linkBlue">
              <% if User.current.member_of_course?(activity.course) || User.current.admin? || activity.is_open == 1 %>
                  <%= link_to image_tag(url_to_avatar(User.find sw.user_id), :width => "40", :height => "40"), student_work_index_url_in_org(activity.id, 2, '', sw.id), :alt => "学生头像" %>
                  <p class="w100 hidden">
                    <%= link_to sw.user.show_name,student_work_index_url_in_org(activity.id, 2, '', sw.id)%>
                  </p>
              <% else %>
                  <%= image_tag(url_to_avatar(User.find sw.user_id), :width => "40", :height => "40", :title => '该作业的作品暂未公开') %>
                  <p class="w100 hidden">
                    <a href="javascript:void(0);" title="该作业的作品暂未公开"><%=sw.user.show_name %></a>
                  </p>
              <% end %>
            </a>
            <% score = sw.respond_to?("score") ? sw.score : (sw.final_score || 0) - sw.absence_penalty - sw.late_penalty %>
            <p class="fontGrey2">分数：<span class="c_red"><%=format("%.1f",score.to_i<0 ? 0 : score.to_i) %>分</span></p>
          </div>
          <% if i == 4 %>
              <% break %>
          <% end %>
      <% end %>
      <% if student_works.count > 5 %>
          <%= link_to "更多>>", student_work_index_url_in_org(activity.id, 2),:class=>'linkGrey2 fl ml50',:style=>'margin-top:60px;'%>
      <% end %>
      <div class="cl"></div>
    </div>
<% end %>
<div class="cl"></div>
<% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1 %>
    <% projects = activity.student_work_projects.where("is_leader = 1") %>
    <% unless projects.empty? %>
        <% sort_projects = project_sort_update projects %>
        <div class="mt10 relatePWrap" id="relatePWrap_<%=user_activity_id %>">
          <div class="mr5 fontGrey2">
            <%# first_pro = sort_projects.first %>
            <% first_pro = Project.find sort_projects.first.project_id %>
            <% commit_time = first_pro.project_score.commit_time %>
            <% one_forge_time=ForgeActivity.where("project_id=?",first_pro.id).last.updated_at if ForgeActivity.where("project_id=?",first_pro.id).last %>
            #&nbsp;<%=time_from_now !commit_time.nil? && format_time(commit_time) > format_time(one_forge_time) ? commit_time : one_forge_time %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目，最近更新：
          </div>
          <div class="cl"></div>
          <% sort_projects.each_with_index do |pro, i| %>
              <% project = Project.find pro.project_id %>
              <script type="text/javascript">
                  $(document).ready(function(){
                      $("#project_img_<%=project.id %>_<%=activity.id %>").mouseover(function(){
                          $("#relatePInfo_<%=project.id %>_<%=activity.id %>").css("display","block");
                      }).mouseout(function(){
                          $("#relatePInfo_<%=project.id %>_<%=activity.id %>").css("display","none");
                      });
                  });
              </script>

              <div class="mr10 mb10 mt10 fl w100 fontGrey2" style="text-align: center;">
                <% com_time = project.project_score.commit_time %>
                <% forge_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %>
                <% if project.is_public || User.current.member_of?(project) || User.current.admin? %>
                    <%= link_to image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius relatePImage"),project_path(project.id,:host=>Setting.host_name),:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像", :target => '_blank' %>
                    <p class="mh18 hidden"><%=link_to (User.find project.user_id).show_name+"(组长)", project_path(project.id,:host=>Setting.host_name), :target => '_blank', :title => "#{(User.find project.user_id).show_name}(组长)" %></p>
                    <% update_time = time_from_now !com_time.nil? && format_time(com_time) > format_time(forge_time) ? com_time : forge_time %>
                    <p class="mh18 hidden"><%=link_to update_time+"  "+project.project_score.changeset_num.to_s+"提交", project_path(project.id,:host=>Setting.host_name), :target => '_blank', :title => "#{update_time}  #{project.project_score.changeset_num.to_s}提交" %></p>
                <% else %>
                    <%= image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius relatePImage",:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像",:title => "私有项目不可访问") %>
                    <p class="mh18 hidden" title="私有项目不可访问"><span class="captainName" title="<%=(User.find project.user_id).show_name %>"><%=(User.find project.user_id).show_name %></span><span style="vertical-align: top;">(组长)</span></p>
                    <p class="mh18 hidden" title="私有项目不可访问"><%=time_from_now !com_time.nil? && format_time(com_time) > format_time(forge_time) ? com_time : forge_time %>&nbsp;&nbsp;<%= project.project_score.changeset_num %>提交</p>
                <% end %>
                <div class="relatePInfo" id="relatePInfo_<%=project.id %>_<%=activity.id %>">
                  项目名称：<%=project.name %><br />
                  创建者：<%=(User.find project.user_id).show_name %>(组长)<br />
                  更新时间：<%=time_from_now !com_time.nil? && format_time(com_time) > format_time(forge_time) ? com_time : forge_time %>
                </div>
              </div>
              <% if i == 9 && projects.count > 10 %>
                  <a href="javascript:void(0);" class="linkGrey2 fl ml50" style="margin-top:68px;" id="moreProject_<%=user_activity_id %>">更多>></a>
              <% end %>
              <% if i > 9 && i == (projects.count - 1) %>
                  <a href="javascript:void(0);" class="linkGrey2 fr mr10" style="margin-top:68px;" id="hideProject_<%=user_activity_id %>">收回&lt;&lt;</a>
              <% end %>
          <% end %>
        </div>
    <% end %>
<% end %>
<div class="cl"></div>

<% if is_teacher%>
    <% comment_status = activity.homework_detail_manual.comment_status %>
    <div class="homepagePostSetting">
      <ul>
        <li class="homepagePostSettingIcon">
          <ul class="homepagePostSettiongText">
            <li>
              <%= link_to l(:button_edit),edit_homework_common_path(activity, :hw_status => hw_status), :class => "postOptionLink"%>
            </li>
            <li>
              <%= link_to(l(:label_bid_respond_delete), homework_common_path(activity, :hw_status => hw_status),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink")  %>
            </li>
            <li>
              <%= link_to("评分设置", score_rule_set_homework_common_path(activity,:user_activity_id => user_activity_id, :hw_status => hw_status),:class => "postOptionLink", :remote => true) %>
            </li>
            <% if activity.anonymous_comment == 0 %>
                <li>
                  <%= link_to("匿评设置", start_evaluation_set_homework_common_path(activity,:user_activity_id => user_activity_id, :hw_status => hw_status),:class => "postOptionLink", :remote => true) if activity.homework_detail_manual.comment_status == 1%>
                </li>
                <li>
                  <%= homework_anonymous_comment activity,hw_status,user_activity_id %>
                </li>
            <% end %>
            <% if activity.anonymous_comment == 0 && (comment_status == 0 || comment_status == 1)%>
                <li>
                  <%= link_to("禁用匿评", alert_forbidden_anonymous_comment_homework_common_path(activity,:user_activity_id => user_activity_id),:class => "postOptionLink",
                              :title => "匿评是同学之间的双盲互评过程：每个同学将评阅系统分配给他/她的若干个作品", :remote => true)%>
                </li>
            <% end %>
            <% if (activity.anonymous_comment == 1 && activity.is_open == 0) || (activity.anonymous_comment == 0 && comment_status == 3 && activity.is_open == 0) %>
                <li>
                  <%= link_to("公开作品", alert_open_student_works_homework_common_path(activity,:user_activity_id => user_activity_id, :hw_status => hw_status),:class => "postOptionLink", :remote => true)%>
                </li>
            <% elsif activity.is_open == 1 %>
                <li>
                  <%= link_to("取消公开", alert_open_student_works_homework_common_path(activity,:user_activity_id => user_activity_id, :hw_status => hw_status),:class => "postOptionLink", :remote => true)%>
                </li>
            <% end %>
          </ul>
        </li>
      </ul>
    </div>
<% end%>