<%# course_model %>
<%# course_file_num = Attachment.where(:container_type => "Course", :container_id => @course.id).count %>

<% course_file_num = visable_attachemnts_incourse(@course).count%>
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %>
<% homework_num = visable_course_homework @course %>

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
  <meta charset="utf-8">
  <title>
    <%= h html_title %>
  </title>
  <meta name="description" content="<%= Redmine::Info.app_name %>"/>
  <meta name="keywords" content="issue,bug,tracker"/>
  <%= csrf_meta_tag %>
  <%= favicon %>
  <%= javascript_heads %>
  <%= heads_for_theme %>
  <%= call_hook :view_layouts_base_html_head %>
  <%= stylesheet_link_tag  'jquery/jquery-ui-1.9.2','css/common','css/public', 'css/structure','prettify', 'css/courses','css/popup','sy_public','syllabus'%>
  <%= javascript_include_tag "course","avatars","header","attachments",'prettify' %>
  <!-- page specific tags -->
  <%= yield :header_tags -%>
  <!-- MathJax的配置 -->
  <script type="text/javascript"
          src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  </script>
  <!--<script type="text/javascript"-->
          <!--src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">-->
  <!--</script>-->
  <!-- 配置 ： 在生成的公式图片上去掉Math定义的右键菜单，$$ $$ \( \) \[ \] 中的公式给予显示-->
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({

    showMathMenu: false,
    showMathMenuMSIE: false,
      tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
    });
  </script>
</head>
<!--add by huang-->
<body onload="prettyPrint();">
<div class="navContainer">
  <% if User.current.logged? %>
      <%= render :partial => 'layouts/logined_header' %>
  <% else%>
      <%= render :partial => 'layouts/unlogin_header' %>
  <% end%>
</div>
<div class="cl"></div>
<div class="">
  <div class="sy_class_infobox pr" id="project_info_<%=@course.id %>">
    <%=render :partial => 'layouts/course_base_info' %>
  </div>

  <div class="sy_content">
    <div class="sy_class_l fl" id="courseLSide">
      <div class="sy_class_leftnav mb12">
        <ul class="accordion">
          <% unless show_nav?(@course.course_activities.count) %>
              <li id="sy_01" class="sy_icons_index">
                <a href="<%=course_path(@course) %>" >动态<span><%=@course.course_activities.count %></span></a>
              </li>
          <% end %>
          <% unless show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %>
              <li id="sy_02" class="sy_icons_boards">
                <% count = @course.boards.first ? (@course.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", @course.boards.first.id, nil).count) : 0 %>
                <a href="<%=course_boards_path(@course) %>">讨论区<span><%=count %></span></a>
                <%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
              </li>
          <% end %>
          <% unless show_nav?(@course.homework_commons.count) %>
              <li id="sy_03" class="sy_icons_hwork">
                <a href="<%= homework_common_index_path(:course => @course.id) %>">作业<span><%=homework_num %></span></a>
                <%= link_to( "",homework_common_index_path(:course => @course.id,:is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_course_homework_new)}") if is_teacher %>
              </li>
          <% end %>
          <% unless show_nav?(@course.news.count) %>
              <li id="sy_04" class="sy_icons_news">
                <a href="<%=course_news_index_path(@course) %>">通知<span><%=@course.news.count %></span></a>
                <%= link_to( "",new_course_news_path(@course,:is_new=>1), :class => 'sy_class_add', :title =>"#{l(:label_course_news_new)}") if is_teacher %>
              </li>
          <% end %>
          <% unless show_nav?(course_file_num) %>
              <li id="sy_05" class="sy_icons_files">
                <a href="<%=course_files_path(@course) %>">资源库<span><%=course_file_num %></span></a>
                <% if is_teacher || (@course.publish_resource == 1  && User.current.member_of_course?(@course)) %>
                    <a class="sy_class_add" title="上传资源" href="javascript:void(0);" onclick="course_files_upload();"> </a>
                <% end %>
              </li>
          <% end %>
          <% unless show_nav?(course_feedback_count) %>
              <li id="sy_06" class="sy_icons_feedback">
                <a href="<%=course_feedback_path(@course) %>">留言<span id="course_jour_count"><%=course_feedback_count %></span></a>
                <%= link_to "", course_feedback_path(@course), :class => 'sy_class_add', :title =>"#{l(:label_course_feedback)}"%>
              </li>
          <% end %>
          <% unless show_nav?(course_poll_count) %>
              <li id="sy_07" class="sy_icons_poll">
                <a href="<%=poll_index_path(:polls_type => "Course", :polls_group_id => @course.id) %>">问卷调查<span><%=course_poll_count %></span></a>
                <%= link_to( "", new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => 'sy_class_add', :title =>"#{l(:label_new_poll)}") if is_teacher %>
              </li>
          <% end %>
          <% count = User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status <> 1").count %>
          <% unless show_nav?(count) %>
              <li id="sy_08" class="sy_icons_exercise">
                <a href="<%=exercise_index_path(:course_id => @course.id) %>">在线测验<span><%=count %></span></a>
                <%= link_to( "", new_exercise_path(:course_id => @course.id), :class => 'sy_class_add', :title =>"新建试卷") if is_teacher %>
              </li>
          <% end %>
          <% group_count = @course.course_groups.count %>
          <% if !show_nav?(group_count) && ((User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin?) %>
              <li id="sy_09" class="sy_icons_group">
                <a href="<%=course_member_path(@course, :role => 2) %>">分班<span><%=group_count %></span></a>
                <!--<a href="javascript:void(0);" class="sy_class_add"></a>-->
              </li>
          <% end %>
          <% statistics_count = 0 %>
          <% unless show_nav?(statistics_count) %>
              <li id="sy_10" class="sy_icons_st">
                <a href="<%=statistics_course_course_path(@course) %>">统计<span></span></a>
                <!--<a href="javascript:void(0);" class="sy_class_add"></a>-->
              </li>
          <% end %>
          <%# 工具栏展开 %>
          <% if @course.homework_commons.count == 0 || @course.news.count == 0 || course_file_num == 0 || course_poll_count == 0 || @course.exercises.count == 0 ||
                  course_feedback_count == 0 || @course.exercises.count == 0 || (@course.boards.first ? @course.boards.first.topics.count : 0) == 0 || statistics_count == 0%>
              <li id="expand_tools_expand" class="sy_icons_more"><a href="javascript:void(0)"> 更多</a>
              </li>
              <ul class="sub-menu undis" id="navContentCourse">
                <%= render :partial => 'courses/tool_expand' %>
              </ul>
          <% end %>
        </ul>
      </div><!--sy_class_leftnav end-->
      <%# 课程活跃度 %>
      <%= render :partial => 'courses/course_activity_users', :locals => {:course => @course} %>
      <%# 课程英雄榜 %>
      <%= render :partial => 'courses/course_heroes', :locals => {:course => @course} %>
      <div class="sy_class_leftbox" >
        <h3 class="fontGrey7">班级推荐</h3>
        <%= render :partial => 'courses/recommendation', :locals => {:course => @course} %>
      </div>
      <%# 更新访问数,刷新的时候更新访问次数 %>
      <%  update_visiti_count @course %>
      <div class="fontGrey5 mt10 ml20">访问计数 <%= @course.visits.to_i %> （自2016年5月）</div>
    </div><!--sy_class_l end-->
    <div class="fl">
      <%= yield %>
    </div><!--sy_class_r end-->
    <div class="cl"></div>
  </div><!--sy_content end-->
</div>

<div class="cl"></div>
<%= render :partial => 'layouts/footer' %>
<div class="cl"></div>

<%= render :partial => 'layouts/new_feedback' %>
<div id="ajax-indicator" style="display:none;">
  <span><%= l(:label_loading) %></span>
</div>
<div id="ajax-modal" style="display:none;"></div>
<div id="nh_tx_dialog_html" class="white_content" style="display:none;">
  <%=render :partial => 'layouts/upload_avatar', :locals => {:source => @course} %>
</div>
<%= call_hook :view_layouts_base_body_bottom %>
</body>
<script>
    var blog_artile_list_html = '';
    $(function(){
        if($("#sy_0<%=@left_nav_type %>").length > 0){
            $("#sy_0<%=@left_nav_type %> a").addClass('active');
        } else {
            $("#expand_tools_expand a").addClass('active');
            $("#navContentCourse").toggle();
        }
        $(document).on('input','input[name="course_outline_search"]',function(e){
            throttle(course_outline_search,window,e);
        });
        function throttle(method,context,e){
            clearTimeout(method.tId);
            method.tId=setTimeout(function(){
                method.call(context,e);
            },500);
        }
        function course_outline_search(e){
//            if($(e.target).val().trim() == ''){
//                return;
//            }
            $("#course_outline_hint").hide();
            $.ajax({
                url:'<%=search_course_outline_course_path(@course) %>'+"?&title="+ e.target.value,
                type:'post',
                success:function(data){

                    if(data.length != 0 ){
                        $("#course_outline_list").html('');
                        for(var i =0;i<data.length;i++){
                            var html = ' <ul class="blogRow"> '+
                                     ' <li class="fl"> '+
                                    '<input name="outline_id" type="radio" value="'+data[i].blog_comment.id+'" class="courseSendCheckbox"/>'+
                                    '</li>'+
                            '<li class="blogTitle fl">'+data[i].blog_comment.title+'</li>'+
                            '</ul>'+
                            '<div class="homeworkPublishTime">发布时间：'+data[i].blog_comment.created_at.match(/(\S*)T/)[1]+'</div>';
                            $("#course_outline_list").append(html)
                        }

                    }else{
                          $("#course_outline_list").html('');
                          $("#course_outline_hint").show();
                    }
                }
            })
        }

    });
    //资源库上传附件
    function course_files_upload(){
            $('#ajax-modal').html('<%= escape_javascript(render :partial => 'files/upload_course_files',:locals => {:course => @course,:course_attachment_type => 1}) %>');
            showModal('ajax-modal', '513px');
            $('#ajax-modal').siblings().remove();
            $('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal()' style='margin-left: 480px;'><img src='/images/bid/close.png' width='26px' height='26px' /></a>");
            $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9");
            $('#ajax-modal').parent().addClass("popbox_polls");
    }
//    鼠标经过的时候显示内容
    function message_titile_show(obj,e)
    {
        obj.parent().parent().next("div").show();
        obj.parent().next("div").css("top",e.pageY).css("left",e.pageX).css("position","absolute");
    }
    function message_titile_hide(obj)
    {
        obj.parent().parent().next("div").hide();
    }

    function message_titile_show2(obj,e)
    {
        obj.parent().next("div").show();
        obj.parent().next("div").css("top",e.pageY).css("left",e.pageX).css("position","absolute");
    }
    function message_titile_hide2(obj)
    {
        obj.parent().next("div").hide();
    }

    $("#expand_tools_expand").click(function(){
        var accordion_head = $('.accordion > li > a');
        accordion_head.removeClass('active');
       $("#expand_tools_expand a").addClass('active');
       $("#navContentCourse").toggle();
    });
</script>

</html>