<?php include('parent/callMe.php');?>
<?php include('Sessioncheck.php');?>
<?php   
  
   if($_REQUEST['class_id']!=NULL){  
  
      if($_REQUEST['class_id']!=NULL){
        $m->where("class_id", $_REQUEST['class_id']);  
      }      
      if($_REQUEST['session']!=NULL){
        $m->where("session_id", $_REQUEST['session']);        
      }
      if($_REQUEST['section']!="All"){
        $m->where("section_id", $_REQUEST['section']);        
      }
     
       $m->where("status", '0');
       $m->where("branch_id", $_SESSION['branch']);

     
       $param = array('student_id','ref_no','first_name','last_name','cell_no','branch_id','class_id','candidate_roll_no','section_id','session_id');
       $WorkAssignListings = $m->get("edu_student_details",null,$param);
 }
      
        $m->where("session_id", $_REQUEST['session']);
        $sessionID=$m->get("edu_session_config");


       // getting branch details

        $m->where("branch_id", $_SESSION['branch']);
        $branch=$m->get("edu_branch_config");
   
        $m->where("term_id", $_REQUEST['term_id']);
        $terms = $m->get("eduportal_exam_terms");


function ordinal($number) {
    $ends = array('th','st','nd','rd','th','th','th','th','th','th');
    if ((($number % 100) >= 11) && (($number%100) <= 13))
        return $number. 'th';
    else
        return $number. $ends[$number % 10];
}

?>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Print Result Sheet</title>
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<script type="text/javascript">
// window.print();
</script>
<style type="text/css">

tr th {border:1px solid black;text-align:center;background-color:lightgray;font-size:13px;}
tr td {border-bottom:1px solid black;border-left:1px solid black;font-size:12px;}
  
.border{border:1px solid black;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}



@media print {
    #Header, #Footer { display: none !important; }
}
@media screen
   {
      p.bodyText {font-family:verdana, arial, sans-serif;}
   }

   @media print
   {
      p.bodyText {font-family:georgia, times, serif;}
   }
   @media screen, print
   {
      p.bodyText {font-size:10pt}
   }
   @media print {
  a[href]:after {
    content: none !important;
  }
}
.center{text-align:center;}

hr.new1 {
  border-top: 1px solid black;
}

</style>
</head>

<body style="font-size:12px;padding-right:1%;padding-left:1%;padding-top:3%;padding-bottom:1%;">

  <div style="width:20%;font-size:13px;text-align:center;float:left;height:80px;">

         <img src="<?php echo DOMAIN.AgentDirectory;?>img/<?php echo $branch[0]['logo']; ?>" style="height:85px;width:85px;margin-top: -13px;" />

  </div>

<div style="text-align:center;font-size:25px;font-weight:bold;margin:0 auto;"><?php echo $branch[0]['Branch_Name'];?> 
</div>

<br>

<div style="text-align:center;font-size:20px;font-weight:bold;"> SINGLE SUBJECT COMPERISON REPORT

 </div>

<hr style="width:100%;">



<br>
   
<table style="width:100%;font-size:16px;" cellspacing="0">

<thead>

<tr>
<th></th>
<th style="padding: 12px;">Class / Section</th>
<th colspan="3"><?php echo getClassName($m,$_REQUEST['class_id']);?>/<?php echo getSectionName($m,$_REQUEST['section']);?></th>

<th style="padding: 12px;">Rounds</th>


<?php 
$termNo=$_REQUEST['noOfterms'];
$branchId=$_SESSION['branch'];
$class=$_REQUEST['class_id'];
$section=$_REQUEST['section'];

$queryT="SELECT * FROM eduportal_exam_marksheet where branch_id='$branchId' and class_id='$class' and section_id='$section' group by term_id limit $termNo ";

$TermsNo = $m->query($queryT);

foreach ($TermsNo as $TermNo) {  

$m->where("term_id", $TermNo['term_id']);
$m->where("branch_id", $_SESSION['branch']);
$m->orderBy("term_title","asc");

$termName = $m->get("eduportal_exam_terms"); 

              

?>

<th width="8%" class=" center"> <?php echo $termName[0]['term_title']; ?> </th> 

<?php  }  ?>

<th colspan="3"></th>


</tr>
            <tr>
                <th width="3%" class=" center">S.No</th>
                <th width="20%" class=" center">Name</th>                
                <th width="7%" class=" center">R.NO</th>
                <th width="7%" class=" center">ADM</th>
                <th width="7%" class=" center">Gender</th>
                <th width="7%" class=" center">Subject <br><hr>Test Date <br><hr>Total Marks</th>
                             
         <?php 
        
          foreach ($TermsNo as $TermNo) {  

          $m->where("term_id", $TermNo['term_id']);
          $m->where("branch_id", $_SESSION['branch']);
          $m->orderBy("term_title","asc");
          
          $termName = $m->get("eduportal_exam_terms"); 


          $m->where("subject_id", $_REQUEST['subject']);
          $m->where("branch_id", $_SESSION['branch']);                  
          $sbjName = $m->get("eduportal_subject_config");

          $totalAllTerms+=$TermNo['total_marks'];               
                           
                ?>

            <th width="8%" class=" center"> <?php echo $sbjName[0]['subject']."<br> <hr>".date("d-M-Y",strtotime($termName[0]['starting_date']))."<br> <hr> ".$TermNo['total_marks']; ?>             
            </th> 

             <?php  }  ?> 
       
               <th width="8%" class=" center"> G.Total </th> 
               
               <th width="8%" class=" center"> %AVG </th>                
               
               <th width="8%" class=" center"> S.Total.AVG </th>             
             
                 
            </tr>
        </thead>
        <tbody>


   
     
       
     <?php 
     $count=1;
     $SR=1;
    

     // getting all the marks of students and other data

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
        $total_marks;
        $total_obt;
   

        $m->where("session_id", $WorkAssignListVal['session_id']);
        $sessionID=$m->get("edu_session_config");
        


        $m->where("subject_id", $WorkAssignListVal['subject_id']);
        $subjects=$m->get("eduportal_subject_config");

             
           
   ?>

<tr>   

<td class=" center" style="padding:3px;"> <?php echo $SR;  $SR++;?> </td>
<td style="padding-left:1%;"><?php echo $WorkAssignListVal['first_name'];  ?></td>

<td class=" center"> <?php echo $WorkAssignListVal['candidate_roll_no'];?> </td>

<td class=" center"> <?php echo $WorkAssignListVal['ref_no'];?> </td>

<td class=" center"> <?php echo $WorkAssignListVal['gender'];?> </td>
<td></td>

<?php
$stdTotalObtain;

foreach ($TermsNo as $TermNo) {  

$m->where("branch_id", $_SESSION['branch']);
$m->where("term_id", $TermNo['term_id']);
$m->where("subject_id", $_REQUEST['subject']);
$m->where("student_id", $WorkAssignListVal['student_id']);

$param5 = array('total_marks','obtained_marks');
$marks = $m->get("eduportal_exam_marksheet",null,$param5);

$stdTotalObtain+=$marks[0]['obtained_marks'];

?>

<td class=" center"> <?php echo $marks[0]['obtained_marks'];?> </td>
              
<?php }  // closing term loop  ?>

<td class=" center"> <?php echo $stdTotalObtain;?> </td>

<td class=" center"> <?php echo number_format($stdTotalObtain*100/$totalAllTerms,1);?>% </td>

<td class=" center" style="border-right: 1px solid black;"> <?php echo $WorkAssignListVal['gender'];?> </td>



</tr>

              

 <?php $stdTotalObtain=""; } // closing main loop  ?>   
           
            
           
        </tbody>
        
    </table>



</body>
</html>
