<?php include('parent/callMe.php');?>
<?php include('Sessioncheck.php');?>
<?php   
  
  
   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']!=NULL){

        $m->where("section_id", $_REQUEST['section']);
        
      }
     
      if($_REQUEST['term_id']!=NULL){

        $m->where("term_id", $_REQUEST['term_id']);
        
      }

        if($_REQUEST['subjects']!=NULL){

        $m->where("subject_id", $_REQUEST['subjects']);
        
      }
   
       $m->where("branch_id", $_SESSION['branch']);
       $WorkAssignListings = $m->get("eduportal_exam_marksheet");

   }
    


        $m->where("class_id", $_REQUEST['class_id']);
        $class=$m->get("edu_class_config");

        $m->where("section_id", $_REQUEST['section']);
        $section=$m->get("edu_adm_section_detail");
       

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



     ?>
<!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 Recent 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">

	.border{border:1px solid black;}
	.center{text-align:center;}
	.alignment{padding-left:1%;text-align:left;}

	tr th {border:1px solid gray; background-color:gray;color:white;text-align:center;}
	tr td {border:1px solid gray;text-align:center;}

     body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        background-color: #FAFAFA;
        font: 12pt "Tahoma";
    }
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }
    .page {
        width: 297mm;
        min-height:auto;        
        padding: 20mm;
        margin: 10mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 5px;
        background: white;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
    }
    .subpage {
        width: 257mm;
        height:auto;
        
    }
    
    @page {
        size: A4 portrait; 
        margin: 0;
    }
    @media print {
        html, body {
            width:297mm;
            height:auto;        
        }
        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: initial;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: blue;
        }
    }


  </style>



</head>
<body style="font-size:12px;">


<div class="book">
  <div class="page">
      <div class="subpage">



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

<br>
<div style="text-align:center;font-size:14px;font-weight:bold;"> <strong>  Recent Result of Last Four Test/Exams   </strong> </div>

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

<div style="width:20%;float:left;">  <b> Class Name:</b> <?php echo $class[0]['Class_Name']."-".$section[0]['section_name'];?> </div>


<div style="text-align:center;width:20%;float:left;"> <b> Session:</b> <?php echo $session[0]['session_year'];?> </div>

<div style="text-align: right;width:20%;float:right;"> <b> Printed:</b> <?php echo date("d-M-Y");?> </div>
<div style="text-align:right;width:20%;float:right;"> <b> Total Strength:</b> <?php echo count($WorkAssignListings);?> </div>

<br>
   

<?php 

    $total=0;
    $total2=0;
    foreach($WorkAssignListings as $WorkAssignListVal)
      { 

        $avg=($WorkAssignListVal['obtained_marks']/$WorkAssignListVal['total_marks'])*100;
        // now find the right grade of each subject

       $query="SELECT grade_id,grade_title FROM eduportal_exam_school_grades WHERE percantage_start_range <=".$avg." and percantage_end_range >=".$avg." and branch_id=".$_SESSION['branch'];
       $grades =  $m->query($query);

       if($grades[0]['grade_title']=="F"){
         $total++;
       }
       else {
        $total2++; 
       }

      }
?>
    

        <table  style="width:100%;font-size:15px;">
              
              
                <tr>
                    <th width="20%">Pass Students:  </th>
                    <th width="40%" style="text-align:left;"> <?php  echo $total2;?> </th>
                </th>
                    <th width="20%">Fail Students:</th>
                    <th width="40%" style="text-align:left;"> <?php  echo $total;?> </th>
          
                </tr>

        </table>     
    

    <table id="listofstudents1" data-page-length='100' class="table table-striped table-bordered" style="width:100%;border-collapse: collapse;">
          
          <thead>
            <tr>
                <th width="3%">S.No</th>
                <th width="15%">Student Name</th>
                <th width="10%">Roll#</th>
                <th width="10%" style="text-align:center;"> Adm No </th>
                <th width="8%" style="text-align:center;"> Subject </th>

                <?php if ($_REQUEST['total_obtain']=="YES") {?>
                <th width="5%" style="text-align:center;"> Total </th>
                <th width="5%" style="text-align:center;"> Obtained </th>
                <?php } ?>
                
                <th width="4%" style="text-align:center;"> % </th>
                <th width="4%" style="text-align:center;"> Grade </th>
                <th width="5%" style="text-align:center;"> Status </th>
                <!-- <th width="5%" style="text-align:center;"> Position </th> -->
                 
            </tr>
        </thead>
        <tbody>


   
     
     <?php $count=1;

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

        $m->where("class_id", $WorkAssignListVal['class_id']);
        $class=$m->get("edu_class_config");

        $m->where("section_id", $WorkAssignListVal['section_id']);
        $section=$m->get("edu_adm_section_detail");

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

        $m->where("status", 0);
        $m->where("branch_id", $_SESSION['branch']);
        $m->where("student_id", $WorkAssignListVal['student_id']);
        $students = $m->get("edu_student_details");


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

        $avg=($WorkAssignListVal['obtained_marks']/$WorkAssignListVal['total_marks'])*100;
        // now find the right grade of each subject

       $query="SELECT grade_id,grade_title FROM eduportal_exam_school_grades WHERE percantage_start_range <=".$avg." and percantage_end_range >=".$avg." and branch_id=".$_SESSION['branch'];


         $average =  $m->query($query);
          

      ?>

        <tr>
                  <td style="text-align:center;"> <?php echo $count; $count+=1;?> </td>
                  <td style="text-align: left;padding-left: 1%;"><?php echo $students[0]['first_name'];?></td>

                  <td> <?php echo $students[0]['candidate_roll_no'];?> </td>

                   <td> <?php echo $students[0]['ref_no'];?> </td>

                 
                  <td style="text-align:center;"> <?php echo $subjects[0]['subject'];?> </td>

                  <?php if ($_REQUEST['total_obtain']=="YES") {?>
                  <td style="text-align:center;"> <?php echo $WorkAssignListVal['total_marks'];?> </td>
                  
                  <td style="text-align:center;"> <?php echo $WorkAssignListVal['obtained_marks'];?> </td>

                  <?php } ?>
                  
                  <td style="text-align:center;"> <?php echo $avg;?>% </td>

                  <td style="text-align:center;"> <?php echo $average[0]['grade_title'];?> </td>

                  <td style="text-align:center;"> <?php if($average[0]['grade_title']=="F"){ ?> 

                  <a target="_blank" style="padding: 0px 5px; font-size:14px;"  class="btn btn-warning">Fail </a>
                  <?php } else {   ?>

                  <a target="_blank" style="padding: 0px 5px; font-size:14px;"  class="btn btn-success">Pass </a>

                  <?php  } ?>
                  </td>


                  <!-- <td style="text-align:center;"> <?php echo $WorkAssignListVal['grade'];?> </td> -->

                 
              </tr>





              <?php
      } ?>



           
            
           
        </tbody>
        
    </table>
  

   

        </div>    
    </div>      
   </div>

 

</body>
</html>
