<?cs include:"util.cs" ?>
<?cs include:"grade_book_menu_util.cs" ?>

<?cs def:print_partial_credit_item(some_value,  item_id, base) ?>
<?cs if:!is_student ?>
  <?cs var:some_value ?><?cs if:base > #0 ?>/<?cs var:base ?><?cs /if ?>
<?cs elif:is_student && score[username][item_id].score ?>
  <?cs var:some_value ?><?cs if:base > #0 ?>/<?cs var:base ?><?cs /if ?>
  <?cs else ?>
  &nbsp;
  <?cs /if ?>
<?cs /def ?>

<?cs def:print_grade_book() ?>
<div>
 <br />
 <table width="100%" cellpadding="4" cellspacing="0" border="1">
 <tr>
    <td colspan="2">
    <span style="color:#f00">**</span> = <?cs var:lang.grade_book.grade_dropped ?><br />
    <span style="color:#f00">*</span>&nbsp;&nbsp;= <?cs var:lang.grade_book.excused ?><br />
    <?cs var:lang.grade_book.extra_credit_label ?> <span class="extra_partial"><?cs var:lang.grade_book.partial ?></span> <span class="extra_all"><?cs var:lang.grade_book.all ?></span>
    </td>
    <?cs set:col = #0 ?>
    <?cs set:cat_num = #0 ?>
    <?cs each:cat = categories ?>

      <?cs if:student_db ?>
      <?cs set:cat_num = cat.number_members - cat.number_hided_items ?>
      <?cs else ?>
       <?cs set:cat_num = cat.number_members ?>
      <?cs /if ?>

    <?cs if:cat_num > #0 ?>
      <?cs if:col % 2 == #0 ?>
       <th class="cateven" align="center" colspan="<?cs var:cat_num ?>">
      <?cs else ?>
        <th class="catodd" align="center" colspan="<?cs var:cat_num ?>" >
      <?cs /if ?>
      <?cs var:cat.cat_name ?><?cs if:calculation_method == "category_weight" ?> <?cs var:cat.cat_weight ?>% <?cs /if ?>
      </th>
    <?cs set:col = col + #1 ?>
    <?cs /if ?>
    <?cs /each ?>

     <?cs if:view_total ?> 
    <td colspan="2" class="total">
     &nbsp;
    </td>
    <?cs /if ?>
    <?cs if:items[9].item_id ?>
    <td colspan="2">
     &nbsp;
    </td>
    <?cs /if ?>
 </tr>
 <tr>
    <th align="center"><?cs var:lang.grade_book.id ?></th>
    <th align="center"><?cs var:lang.grade_book.name ?></th>
    <?cs set:num_cat = #-1 ?>
    <?cs set:prev_cat_id = #-1 ?>
  <?cs each:cat = categories ?>
    <?cs if:student_db ?>
      <?cs set:cat_num = cat.number_members - cat.number_hided_items ?>
    <?cs else ?>
      <?cs set:cat_num = cat.number_members ?>
    <?cs /if ?>

   <?cs if:cat_num > #0 ?>
    <?cs each:item = items ?>
     <?cs if:item.cat_id == cat.cat_id ?>

        <?cs if:item.extra_credit == "partial" ?>
           <th class="extra_partial" align="center" nowrap="nowrap">
        <?cs elif:item.extra_credit == "all" ?>
          <th class="extra_all" align="center" nowrap="nowrap">
        <?cs elif:num_cat % 2 == #0 ?>
          <th class="cateven" align="center" nowrap="nowrap">
        <?cs else ?>
           <th class="catodd" align="center" nowrap="nowrap">
       <?cs /if ?>

      <?cs if:student_db ?>
        <?cs if:item.extra_credit == "partial" ?>
            <?cs call:print_partial_credit_item(item.item_name,  item.item_id, 0) ?>
	<?cs else ?>
           <?cs var:item.item_name ?>
        <?cs /if ?>
      <?cs else ?>
	   <?cs if:item.hide == "yes" ?>
       <i>(<a href="javascript:openWindow('grade_book_enter_grades?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:item.item_id ?>', 'entergrades')"><?cs var:item.item_name ?></a>)</i>
       <?cs else ?>
      <a href="javascript:openWindow('grade_book_enter_grades?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:item.item_id ?>', 'entergrades')"><?cs var:item.item_name ?></a>
      <?cs /if ?>
      <?cs /if ?> 
        </th>
    <?cs /if ?>
    <?cs /each ?> 
   <?cs /if ?>
 <?cs /each ?>

    <?cs if:view_total ?>
    <td class="total"><?cs var:lang.grade_book.Total ?></td>
    <td class="total"><?cs var:lang.grade_book.Grade ?></td>
    <?cs /if ?>
    <?cs if:items[9].item_id ?>
    <th align="center"><?cs var:lang.grade_book.id ?></th>
    <th align="center"><?cs var:lang.grade_book.name ?></th>
    <?cs /if ?>
 </tr>


  <?cs each:student = std ?>
  <tr>
     <th><?cs var:student.id ?></th>
     <th nowrap="nowrap"><?cs var:student.realname ?></th>
     <?cs each:item = items ?>
     <td nowrap="nowrap">
       <?cs if:score[student.username][item.item_id].excuse == "yes" ?>
        <span style="color:#f00">*</span>
       <?cs elif:score[student.username][item.item_id].drop == "yes" ?>
        <span style="color:#f00">**</span>
       <?cs /if ?>
       <?cs if:item.grade_entered == "no" ?>
          <?cs if:item.is_letter_grade == "yes" ?>
             na
	  <?cs else ?>
             na/<?cs var:item.item_points ?>
	  <?cs /if ?>
       <?cs elif:score[student.username][item.item_id].pending == "yes" ?>
          <?cs if:item.is_letter_grade == "yes" ?>
	     ----
	  <?cs else ?>
             ----/<?cs var:item.item_points ?>
	  <?cs /if ?>
       <?cs elif:score[student.username][item.item_id].letter  ?>
            <?cs if:student_db ?>
             <a href="javascript:openWindow('grade_book_std_comment?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:item.item_id ?>&username=<?cs var:student.username ?>', 'stdwind')" title="<?cs var:lang.grade_book.view_comment ?>"><?cs var:score[student.username][item.item_id].letter ?></a>

	    <?cs else ?>
             <?cs var:score[student.username][item.item_id].letter ?>
	    <?cs /if ?>
       <?cs elif:score[student.username][item.item_id].score >= #0  ?>
            <?cs if:student_db ?>
             <a href="javascript:openWindow('grade_book_std_comment?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:item.item_id ?>&username=<?cs var:student.username ?>', 'stdwind')" title="<?cs var:lang.grade_book.view_comment ?>"><?cs var:score[student.username][item.item_id].score ?>/<?cs var:item.item_points ?></a>
	    <?cs else ?>
             <?cs var:score[student.username][item.item_id].score ?>/<?cs var:item.item_points ?>
	     <?cs /if ?>
      <?cs else ?>
             <?cs if:item.extra_credit == "partial" ?>
               <?cs call:print_partial_credit_item("na",  item.item_id, item.item_points) ?>
	     <?cs else ?>
             na/<?cs var:item.item_points ?>
	     <?cs /if ?>
      <?cs /if ?>
     </td>
     <?cs /each ?>
     <?cs if:view_total ?> 
     <?cs if:has_total[student.username] ?>
     <td class="total"><?cs var:score[student.username].total ?></td>
     <td class="total"><?cs var:score[student.username].grade ?></td>
     <?cs else ?>
     <td class="total"> &nbsp;</td>
     <td class="total"> &nbsp;</td>
     <?cs /if ?>
     <?cs /if ?>
     <?cs if:items[9].item_id ?>
       <th><?cs var:student.id ?></th>
       <th nowrap="nowrap"><?cs var:student.realname ?></th>
     <?cs /if ?>
   </tr>
  <?cs /each ?> 

  <?cs if:max_min_avg ?>
  <tr class="stat">
       <td colspan="2" align="center"><?cs var:lang.grade_book.min ?></td>
  <?cs each:item = items ?>
       <?cs if:item.min >= #0 ?>
        <?cs if:item.extra_credit == "partial" ?>
            <td><?cs call:print_partial_credit_item(item.min,  item.item_id, 0) ?></td>
	 <?cs else ?>
             <td><?cs var:item.min ?></td>
	<?cs /if ?>
       <?cs else ?>
        <?cs if:item.extra_credit == "partial" ?>
            <td><?cs call:print_partial_credit_item("na",  item.item_id, 0) ?></td>
        <?cs else ?>  
           <td>na</td>
        <?cs /if ?>
     <?cs /if ?>
  <?cs /each ?>
     <?cs if:view_total ?> 
  <td><?cs var:min ?></td>
  <td><?cs var:min_grade ?></td>
       <?cs /if ?>
     <?cs if:items[9].item_id ?>
       <td colspan="2" align="center"><?cs var:lang.grade_book.min ?></td>
     <?cs /if ?>
  </tr>
  <tr class="stat">
       <td colspan="2" align="center"><?cs var:lang.grade_book.max ?></td>
  <?cs each:item = items ?>
     <?cs if:item.max >= #0 ?>
        <?cs if:item.extra_credit == "partial" ?>
            <td><?cs call:print_partial_credit_item(item.max,  item.item_id, 0) ?></td>
	 <?cs else ?>
        <td><?cs var:item.max ?></td>
	<?cs /if ?>
     <?cs else ?>
        <?cs if:item.extra_credit == "partial" ?>
            <td><?cs call:print_partial_credit_item("na",  item.item_id, 0) ?></td>
        <?cs else  ?>  
        <td>na</td>
       <?cs /if ?>
    <?cs /if ?>
  <?cs /each ?>
     <?cs if:view_total ?> 
  <td><?cs var:max ?></td>
  <td><?cs var:max_grade ?></td>
    <?cs /if ?>
     <?cs if:items[9].item_id ?>
       <td colspan="2" align="center"><?cs var:lang.grade_book.max ?></td>
     <?cs /if ?>
  </tr>
  <tr class="stat">
       <td colspan="2" align="center"><?cs var:lang.grade_book.avg ?></td>
  <?cs each:item = items ?>
       <?cs if:item.avg >= #0 ?>
           <?cs if:item.extra_credit == "partial" ?>
            <td><?cs call:print_partial_credit_item(item.avg,  item.item_id, 0) ?></td>
	  <?cs else ?>
              <td><?cs var:item.avg ?></td>
	    <?cs /if ?>
       <?cs else ?>
        <?cs if:item.extra_credit == "partial" ?>
            <td><?cs call:print_partial_credit_item("na",  item.item_id,0) ?></td>
        <?cs else  ?>  
        <td>na</td>
       <?cs /if ?>
     <?cs /if ?>
  <?cs /each ?>
     <?cs if:view_total ?> 
  <td><?cs var:avg ?></td>
  <td><?cs var:avg_grade ?></td>
  <?cs /if ?>
     <?cs if:items[9].item_id ?>
       <td colspan="2" align="center"><?cs var:lang.grade_book.avg ?></td>
     <?cs /if ?>
  </tr>
  <?cs /if ?>
  <?cs if:view_bar ?>
  <tr>
       <td colspan="2" align="center"><?cs var:lang.grade_book.bargraph ?></td>
  <?cs each:item = items ?>
       <?cs if:item.grade_entered == "yes" ?>
        <?cs if:is_student ?>
	   <?cs if:score[username][item.item_id].score >= #0 ?>
        <td><a href="javascript:openWindow('grade_book_std_bar_graph?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:item.item_id ?>', 'barwin')" title="<?cs var:lang.grade_book.bargraph_help ?>" ><img src="<?cs var:image_path ?>bargraph.gif" alt="" /></a></td>
	   <?cs else ?>
	    <td>&nbsp;</td>
	   <?cs /if ?>
	<?cs else ?>
	  <?cs if:item.max >= #0 ?>
        <td><a href="javascript:openWindow('<?cs if:student_db ?>grade_book_std_bar_graph<?cs else ?>grade_book_bar_graph<?cs /if ?>?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:item.item_id ?>', 'barwin')" title="<?cs var:lang.grade_book.bargraph_help ?>" ><img src="<?cs var:image_path ?>bargraph.gif" alt="" /></a></td>
          <?cs else ?>
	  <td>&nbsp;</td>
	  <?cs /if ?>  
	<?cs /if ?> 
	<?cs else ?>
        <?cs if:item.extra_credit == "partial" ?>
            <td><?cs call:print_partial_credit_item("na",  item.item_id, 0) ?></td>
        <?cs else  ?>  
        <td>&nbsp;</td>
       <?cs /if ?>
     <?cs /if ?>
  <?cs /each ?>
     <?cs if:view_total && avg ?> 
        <td><a href="javascript:openWindow('<?cs if:student_db ?>grade_book_std_bar_graph<?cs else ?>grade_book_bar_graph<?cs /if ?>?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=-2', 'barwin')" title="<?cs var:lang.grade_book.bargraph_help ?>" ><img src="<?cs var:image_path ?>bargraph.gif" alt="" /></a></td>
        <td><a href="javascript:openWindow('<?cs if:student_db ?>grade_book_std_bar_graph<?cs else ?>grade_book_bar_graph<?cs /if ?>?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=-1', 'barwin')" title="<?cs var:lang.grade_book.bargraph_help ?>" ><img src="<?cs var:image_path ?>bargraph.gif" alt="" /></a></td>
	<?cs elif:view_total ?>
        <td>&nbsp;</td><td>&nbsp;</td>	
	<?cs /if ?>
     <?cs if:items[9].item_id ?>
       <td colspan="2" align="center"><?cs var:lang.grade_book.bargraph ?></td>
     <?cs /if ?>
  </tr>
 <?cs /if ?>
 </table>
 </div>
<?cs /def ?>
		

<?cs def:print_close_window() ?>
<?cs call:course_info() ?>
<div>
 <a href="javascript:window.close()" title="<?cs var:lang.grade_book.closewindow ?>" ><img src="<?cs var:image_path ?>close.gif" alt="" /></a>
</div>
<?cs /def ?>

<?cs def:print_grade_book_menu() ?>
<br />
  <ul id="tabmenu">
   <li><a class="active" href="#" title="<?cs var:lang.grade_book.view_std_grade_book ?>" ><?cs var:lang.grade_book.view_std_grade_book ?></a></li>
  </ul> 
<?cs /def ?>

<?cs ###########################
     # HTML starts here
     ###########################
?>
<?cs call:html_heading() ?>
   <head>
      <title><?cs var:course_title ?> <?cs var:lang.grade_configure.scale_heading ?></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <meta http-equiv="Cache-Control" content="No-Cache" />
   <meta http-equiv="EXPIRES" content="Mon, 22 Jul 1997 11:12:01 GMT" />
   <meta http-equiv="PRAGMA" content="No-Cache" />

   <link rel="StyleSheet" href="<?cs var:image_path ?>grade_tab_menu.css" type="text/css"  />
   <script type="text/javascript" src="<?cs var:image_path ?>form_validation.js">
   </script>
   <script type="text/javascript">
   function openWindow(url, winname)
   {
	var new_window = window.open(url, winname,'menubar=0,toolbar=0,status=0,scrollbars=yes,resizable=yes,width=850,height=400,screenX=150,screeny=200,left=150,top=200');
       new_window.focus();
   }
   </script>
</head>


<?cs call:define_body() ?> 
<div id="container">
<?cs if:student_db ?>
    <?cs if:back_url ?>
       <?cs call:print_course_heading(back_url, lang.grade_book.go_back ) ?>
    <?cs else ?>
        <?cs call:print_close_window() ?>
    <?cs /if ?>
<div>
<br />
<br />
  <?cs call:print_grade_book_menu() ?>
</div>
<div id="content">
<?cs call:print_grade_book() ?>
</div>
</div>
<?cs else ?>
<?cs call:print_course_heading(back_url, lang.grade_book_menu_util.goback) ?>
<div>
<br />
<br />
  <?cs call:grade_menu()  ?>
</div>
<div id="content">
<?cs call:print_grade_book() ?>
</div>
</div>
<?cs /if ?>
</body>
</html>
<?cs call:runtime() ?>
