<?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">
 <caption><b><?cs var:std[0].realname ?> <?cs var:std[0].username ?> (<?cs var:std[0].id ?>)</b><br /></caption> 
 <tr>
    <td style="width: 15%">
    <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>
    <th style="width: 10%"><?cs var:lang.grade_book.name ?></th>
    <th style="width: 5%"><?cs var:lang.grade_book.score ?></th>
    <th><?cs var:lang.grade_book.comments ?></th>
   <?cs if:max_min_avg ?>
    <th class="stat" style="width: 5%"><?cs var:lang.grade_book.min ?></th>
    <th class="stat" style="width: 5%"><?cs var:lang.grade_book.max ?></th>
    <th class="stat" style="width: 5%"><?cs var:lang.grade_book.avg ?></th>
   <?cs /if ?> 
   <?cs if:view_bar ?>
    <th class="stat" style="width: 5%"><?cs var:lang.grade_book.bargraph ?></th>
   <?cs /if ?> 
  </tr>
  <?cs set:myCatCount = #0 ?>
   <?cs each:cat = categories ?>
         <?cs if:myCatCount % 2 == #0 ?>
           <tr class="cateven">
	 <?cs else ?>
           <tr class="catodd">
	 <?cs /if ?>
               <th rowspan="<?cs var:cat.number_members ?>">
               <?cs var:cat.cat_name ?><br />
               <?cs var:cat.cat_weight ?>%
               </th> 
      <?cs set:myid = #0 ?> 
      <?cs each:item = items ?>
       <?cs if:item.cat_id == cat.cat_id ?>
         <?cs if:myid != #0 ?>
         <?cs if:myCatCount % 2 == #0 ?>
           <tr class="cateven">
	 <?cs else ?>
           <tr class="catodd">
	 <?cs /if ?>
	 <?cs /if ?>
             <?cs if:item.extra_credit == "partial" ?>
  	     <td class="extra_partial">        
	     <?cs elif:item.extra_credit == "all" ?>          
	     <td class="extra_all"> 
	     <?cs else ?>
	     <td>
	     <?cs /if ?>
	        <?cs if:item.extra_credit ==  "partial" ?>
		  <?cs if:score[std[0].username][item.item_id].letter || score[std[0].username][item.item_id].score >=0 ?> 
                   <?cs var:item.item_name ?> 
		   <?cs else ?>
                   <?cs /if ?>
		<?cs else ?>
                 <?cs var:item.item_name ?> 
		<?cs /if ?>
              </td>
              <td>
	        <?cs if:item.extra_credit ==  "partial" ?>
		  <?cs if:score[std[0].username][item.item_id].letter ?>
		  <?cs var:score[std[0].username][item.item_id].letter ?>
		     
		  <?cs elif:score[std[0].username][item.item_id].score >=0 ?>
		    <?cs var:score[std[0].username][item.item_id].score ?>/<?cs var:item.item_points ?>
		    
		  <?cs /if ?>
                 <?cs elif:item.grade_entered == "no" ?>
	           na<?cs if:item.is_letter_grade == "no" ?>/<?cs var:item.item_points ?><?cs /if ?>
                   <?cs elif:score[std[0].username][item.item_id].pending == "yes" ?>
	            ---<?cs if:item.is_letter_grade == no ?>/<?cs var:item.item_points ?><?cs /if ?>
                   <?cs elif:score[std[0].username][item.item_id].letter ?>
                   <?cs if:score[std[0].username][item.item_id].drop == "yes" ?><span style="color:#f00">**</span><?cs /if ?>
                   <?cs if:score[std[0].username][item.item_id].excuse== "yes" ?><span style="color:#f00">*</span><?cs /if ?>
                    <?cs var:score[std[0].username][item.item_id].letter ?>
                   <?cs elif:score[std[0].username][item.item_id].score >= #0 ?>
                   <?cs if:score[std[0].username][item.item_id].drop == "yes" ?><span style="color:#f00">**</span><?cs /if ?>
                   <?cs if:score[std[0].username][item.item_id].excuse== "yes" ?><span style="color:#f00">*</span><?cs /if ?>
                   <?cs var:score[std[0].username][item.item_id].score ?>/<?cs var:item.item_points ?>
	         <?cs else ?>
	           na<?cs if:item.is_letter_grade == "no" ?>/<?cs var:item.item_points ?><?cs /if ?>
                  <?cs /if ?>
               </td>
	       <td style="width: 10%">
                   <?cs if:score[std[0].username][item.item_id].comments ?>
                   <?cs var:score[std[0].username][item.item_id].comments ?>
		   <?cs else ?>
		    &nbsp; 
		   <?cs /if ?>
	       </td>
                 <?cs if:max_min_avg ?>
	       <td class="stat">
	        <?cs if:item.extra_credit ==  "partial" ?>
		  <?cs if:score[std[0].username][item.item_id].letter || score[std[0].username][item.item_id].score >=0 ?>
                      
	          <?cs var:item.min ?> 
		 <?cs /if ?> 
                 <?cs elif:item.grade_entered == "no" ?>
		    na
		 <?cs else ?>
	          <?cs var:item.min ?>  
		 <?cs /if ?> 
	       </td>
	       <td class="stat">
	        <?cs if:item.extra_credit ==  "partial" ?>
		  <?cs if:score[std[0].username][item.item_id].letter || score[std[0].username][item.item_id].score >=0 ?>
	          <?cs var:item.max ?>  
		  <?cs /if ?>
                 <?cs elif:item.grade_entered == "no" ?>
		    na
		 <?cs else ?>
	          <?cs var:item.max ?>  
		 <?cs /if ?> 
	       </td>
	       <td class="stat">
	        <?cs if:item.extra_credit ==  "partial" ?>
		  <?cs if:score[std[0].username][item.item_id].letter || score[std[0].username][item.item_id].score >=0 ?>
	          <?cs var:item.avg ?> 
		   <?cs /if ?> 
                 <?cs elif:item.grade_entered == "no" ?>
		    na
		 <?cs else ?>
	          <?cs var:item.avg ?>  
		 <?cs /if ?> 
	       </td>
	      <?cs /if ?>
              <?cs if:view_bar ?>
	       <td class="stat">
	        <?cs if:item.extra_credit ==  "partial" ?>
		  <?cs if:score[std[0].username][item.item_id].letter || score[std[0].username][item.item_id].score >=0 ?>
	      <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>
	      <?cs /if ?>
	       <?cs elif:item.grade_entered == "yes" ?>
	      <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>
	      <?cs else ?>
	       &nbsp;   
	      <?cs /if ?>
	       </td>
	      <?cs /if ?>
	      
           </tr> 
      <?cs set:myid = myid + #1 ?> 
      <?cs /if ?>
     <?cs /each ?>
  <?cs set:myCatCount = myCatCount + #1 ?>
   <?cs /each ?>
   <tr class="total">
      <th colspan="2" align="center">
      <?cs var:lang.grade_book.Total ?>
      </th>
      <?cs if:has_total[std[0].username] ?>
       <td>
          <?cs var:score[std[0].username].total ?>
       </td>
      <?cs else ?>
       <td>&nbsp;</td>
      <?cs /if ?> 
      <td>&nbsp;</td>
      <td><?cs var:min ?></td>
      <td><?cs var:max ?></td>
      <td><?cs var:avg ?></td>
      <td></td>
   </tr>
   <tr class="total">
      <th colspan="2" align="center">
      <?cs var:lang.grade_book.Grade ?>
      </th>
      <?cs if:has_total[std[0].username] ?>
       <td>
          <?cs var:score[std[0].username].grade ?>
       </td>
      <?cs else ?>
       <td>&nbsp;</td>
      <?cs /if ?> 
      <td>&nbsp;</td>
      <td><?cs var:min_grade ?></td>
      <td><?cs var:max_grade ?></td>
      <td><?cs var:avg_grade ?></td>
      <td></td>
   </tr>
 </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: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>
</body>
</html>
<?cs call:runtime() ?>
