<%-# Fedena
#Copyright 2010 Foradian Technologies Private Limited
#
#This product includes software developed at
#Project Fedena - http://www.projectfedena.org/
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing,
#software distributed under the License is distributed on an
#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#KIND, either express or implied.  See the License for the
#specific language governing permissions and limitations
#under the License. -%>
<script>
  function check_blanks()
  {
    var blank_marks = 0;
    $$('.marks-box').each(function(marks) {if(marks.value==""){blank_marks=1;} });
    if(blank_marks==1)
    {
      if (!confirm('Students with no marks will be marked as absent. Do you want to continue?')) return false;
      else return true;
    }
    else return true;
  }
</script>
<div id="content-header">
  <%= image_tag("/images/examination/show_exam.png") %>
  <h1><%= t('exams_text') %></h1>
  <h3><%= t('result_entry') %></h3>
  <div id="app-back-button">
    <%= link_to_function image_tag("/images/buttons/back.png",:border => 0), "history.back()" %>
  </div>
</div>
<div id="page-yield">

  <% unless flash[:notice].nil? %>
    <p class="flash-msg"> <%= flash[:notice] %> </p>
  <% end %>
  <% unless flash[:warn_notice].nil? %>
    <div id="errorExplanation" class="errorExplanation"><p><%= flash[:warn_notice] %></p> </div>
  <% end %>
  <div class="bread_crumb">
    <%= link_to t('exams_text'), :controller => "exam", :action=>"index" %> &raquo;
    <%= link_to "#{t('exam_management')}", :controller => "exam", :action => "create_exam" %> &raquo;
    <%= link_to "#{t('previous_batch_exam')}", :controller => "exam", :action => "previous_batch_exams" %> &raquo;
    <%= @exam.subject.name %>
  </div>
  <div class="box">
    <% form_for :exam_scores, :url => {:controller=>"exam", :action=>"update_previous_marks", :exam_id=>@exam.id} do |f| %>

      <table id="listing" width="100%">
        <tr class="tr-head">
          <td><%= t('name') %></td>
          <% unless @exam_group.exam_type == 'Grades' %>
            <td><%= t('marks') %></td>
          <% else %>
            <td><%= t('grades') %></td>
          <% end %>
          <td><%= t('remarks') %>(<%= t('absent_disqualified_etc') %>)</td>
          <% unless @exam_group.exam_type == 'Marks' %>
            <td><%= t('grade') %></td>
          <% end %>
          <td>Retake</td>
        </tr>
        <% @students.each do |student| %>
          <tr class="tr-<%= cycle('odd', 'even') %>">
            <td class="col-2"><%= student.full_name %> </td>
            <% @exam_score = @exam.score_for(student) %>
            <% unless @exam_group.exam_type == 'Grades' %>
              <td class="col-1"><div class="label-field-pair">
                  <div class="text-input-bg">
                    <%= text_field_tag "exam[#{student.id}][marks]", @exam_score.marks, :size => '4', :class=>"marks-box" %></div></div></td>
            <% else %>
              <td class="col-2"><div class="label-field-pair">
                  <div class="text-input-bg"><%= select "exam[#{student.id}]", "grading_level_id", @grades.map {|g| [g.name, g.id] },
                      { :prompt =>"#{t('select_grade')}", :selected => @exam_score.grading_level_id},:class=>"marks-box" %></div></div></td>
            <% end %>

            <td class="col-2"><div class="label-field-pair2">
                <div class="text-input-bg2">
                  <%= text_field_tag "exam[#{student.id}][remarks]", @exam_score.remarks, :size => '40' %></div></div></td>
            <% unless @exam_group.exam_type == 'Marks' %>
              <td class="col-1"><%= @exam_score.grading_level %></td>
            <% end %>
            <td class="col-1"><%= check_box_tag "student_ids[]", student.id,false,{:class=>'right',:id=>"check#{student.id}"} %></td>
          </tr>

        <% end %>

      </table>
      <div id="sub-button"><%= submit_tag "", :value => "► #{t('save')}", :class => "submit_button", :onClick => "if(check_blanks()==true) return true; else return false;" %></div>
    <% end %>

    <div class="extender"></div>
  </div>
</div>
