<?php include('parent/callMe.php');?>

<?php include('Sessioncheck.php');?>

<?php   

/*

error_reporting(E_ALL);

ini_set('display_errors', '1');*/

  

  $tablePadding;

  if ($_REQUEST['attendance']=="Yes" || $_REQUEST['acadmicPerformance']=="Yes" ) {

    

    $tablePadding=".8%";



  } else {



    $tablePadding="1.8%";

  }



   //echo $tablePadding;

     $m->where("branch_id", $_SESSION['branch']);

     $header = $m->get("eduportal_upload_acadmic_signature");

   

   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']);



       $WorkAssignListings = $m->get("edu_student_details");

 }





       // 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];

}



    $m->where("branch_id", $_SESSION['branch']);

    $acadmic_heads = $m->get("eduportal_acadmic_heads");



    $m->where("session_id", $_SESSION['current_session']);

    $sessionName = $m->get("edu_session_config");



    $m->where("branch_id", $_SESSION['branch']);

    $signatures = $m->get("eduportal_upload_acadmic_signature");



 ?>





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

<!-- Favicons-->

<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />

<title> Student Report Card</title>

<!-- Favicons-->

<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />



<script type="text/javascript">

  //window.print();

</script>

<style> 



.section{width:94%; height:28.5cm;float:left;margin:0 auto;padding:1%;margin-left:1%;}

 

 tr td {

    

    padding:.8%;

    /*font-size: 13px;*/

 }



  tr th {

    padding:.8%;

    /*font-size:14px;*/

    background:lightgray; 

 }



.tdalign{text-align:center;border:1px solid black;} 



body {

  background: rgb(204,204,204);

  font-weight:; 

}

page {

  background: white;

  display: block;

  margin: 0 auto;

  margin-bottom: 0.5cm;

  border:1px solid black;

  box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);

  

}

page[size="A4"] {  

  width: 21cm;

  height: 29.7cm; 

}

page[size="A4"][layout="landscape"] {

  width: 29.7cm;

  height: 21cm;  

}

page[size="A3"] {

  width: 29.7cm;

  height: 42cm;

}

page[size="A3"][layout="landscape"] {

  width: 42cm;

  height: 29.7cm;  

}

page[size="A5"] {

  width: 14.8cm;

  height: 21cm;

}

page[size="A5"][layout="landscape"] {

  width: 21cm;

  height: 14.8cm;  

}

@media print {

  body, page {

    margin: 0;

    box-shadow: none;

    border:none;

  

  }

}







#bottom-stuff {



    position: relative;

}



#bottom{



    position: fixed; 

    background:gray; 

    width:100%;

    bottom:0;

}

  </style>





</head>

<body >

  

     <?php 

     $count=1;

     $SR=1;

     $new_array = array();



     // getting all the marks of students and other data



      foreach($WorkAssignListings as $WorkAssignListVal)

      { 

        $total_marks;

        $total_obt;







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

        $class=$m->get("edu_class_config");



    

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

        $session=$m->get("edu_session_config");





     

        /*$m->where("subject_id", $WorkAssignListVal['subject_id']);

        $subjects=$m->get("eduportal_subject_config");*/



        // getting status of students marks





          $m->where("branch_id", $_SESSION['branch']);

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

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

          $m->where("student_id", $WorkAssignListVal['student_id']);

          $sms_status = $m->get("eduportal_exam_marksheet");





              



          // printing all the relevant subjects of each class

                     

                            

          $qrr="SELECT csb.*,sb.* FROM eduportal_class_subjects as csb,eduportal_subject_config as sb WHERE csb.session_id=".$_REQUEST['session']." and csb.class_id=".$_REQUEST['class_id']." and csb.section_id=".$WorkAssignListVal['section_id']." and csb.branch_id=".$_SESSION['branch']." and csb.subject_id=sb.subject_id order by csb.subject_order asc";



         // echo $qrr; 



              $teacher_sbj = $m->query($qrr);

              $sbs_marks="";

              $sbs_tmarks="";

              $sbs_title="";

              $sbs_msg1;



  

              foreach($teacher_sbj as $teacher_sb) {



                



                $m->where("branch_id", $_SESSION['branch']);

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

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

                $m->where("subject_id", $teacher_sb['subject_id']);

                $m->where("student_id", $WorkAssignListVal['student_id']);

                $marks = $m->get("eduportal_exam_marksheet"); 



                if ($marks[0]['obtained_marks']==NULL || $marks[0]['obtained_marks']=="" ) {

                  continue;

                }



                $total_marks+=$marks[0]['total_marks'];

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



                $sbs_marks=$marks[0]['obtained_marks'].",".$sbs_marks;              

                



                  if($marks[0]['obtained_marks']!=NULL && $marks[0]['obtained_marks']!=""){

                  

                  $val=mb_substr($teacher_sb['subject'], 0, 2, "UTF-8")." ".$marks[0]['obtained_marks']."/".$marks[0]['total_marks'];

                  $sbs_msg1=$val.",".$sbs_msg1;              

    

                  }





               

                } // closing subjects marks loop

                

             $avg=($total_obt/$total_marks)*100;

             $avg=intVal($avg+0);

             // getting average of total marks

           $query="SELECT * FROM eduportal_exam_school_grades WHERE percantage_start_range <=".round($avg)." and percantage_end_range >=".round($avg)." and branch_id=".$_SESSION['branch'];

     

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

        

               $new_array['name_cell']=$WorkAssignListVal['first_name'];

               $new_array['roll']=$WorkAssignListVal['candidate_roll_no'];

               $new_array['ref_no']=$WorkAssignListVal['ref_no'];

               $new_array['sub_marks']=$sbs_marks;

               $new_array['total_marks']=$total_marks;

               $new_array['obt_marks']=$total_obt;

               $new_array['percantage']=number_format($avg,2);

               $new_array['grade']=$average[0]['grade_title'];

               $new_array['branch_id']=$_SESSION['branch'];

               $new_array['session']=session_id();

               $new_array['sms']=$sms_status[0]['sms_status'];

               $new_array['student_id']=$WorkAssignListVal['student_id'];

               $new_array['cell_no']=$WorkAssignListVal['cell_no'];

               $new_array['sbs_total']=$sbs_msg1;

               $new_array['last_name']=$WorkAssignListVal['last_name'];

               if(isset($WorkAssignListVal['image'])){

                $new_array['img']=$WorkAssignListVal['image'];

                }else {

                $new_array['img']=""; 

                }



               $new_array['class_id']=$WorkAssignListVal['class_id'];

               $new_array['section_id']=$WorkAssignListVal['section_id'];

               

        

        

              // print_r($new_array);            

               $m->insert("eduportal_exam_temp_marks",$new_array); 

  



  $total_marks=0; $total_obt=0;  $sbs_msg1="";



  }// closing main loop    

    







  $query="select * from eduportal_exam_temp_marks where branch_id=".$_SESSION['branch']." order by cast(obt_marks as decimal(38,10)) DESC";

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

  // echo $query;



  //print_r($std_data);



  $pos=1;

  $Failsub=0;

  for($i=0;$i<count($std_data);$i++) { ?>





<page size="A4"> 



 <!-- Vouchere Fist -->

<div class="section">



  <?php if ($_REQUEST['header']=="Yes") { ?>    

  

 

  <div style="width:100%;float:left;">

  

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



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



      </div>





      

      <div style="width:82%; float:left;text-align:center;">



         <span style="font-size:<?php echo $_REQUEST['schoolHeading_font_size'];?>px;font-family: Times New Roman;font-weight: bold;">  <?php echo $branch[0]['Branch_Name'];?> </span>

         <p style="text-align:center;"><b><?php echo $branch[0]['Branch_Location'];?></b></p>

         <p style="text-align:center;"><b><?php echo $branch[0]['branch_contact'];?></b></p>





      </div>





  </div>



<?php } ?>



<?php if ($_REQUEST['header']=="Custom") { ?>



      <div style="width:100%; height: 9%;">

        <img src="<?php echo DOMAIN;?>Production/signatures/<?php echo $signatures[0]['upload_resultcard_header'];?>" id="preview" style="width:100%;height:108px;"   />

      </div>

      <!--  -->





<?php } ?>





<?php if ($_REQUEST['header']=="No") { ?>



      <div style="width:100%; height: 13%;color:white;">

        .

      </div>

      



<?php } ?>





   <br>

    

        <div style="background-color: <?php echo $_REQUEST['color']?>; color:<?php echo $_REQUEST['font_color']?>;">

            <div style="width:77%;float: left;background-color: <?php echo $_REQUEST['color'];?>; color:<?php echo $_REQUEST['font_color']?>; padding: 8px; border:1px solid black;text-align: center;"><b style="font-size:17px;">RESULT CARD</b> <b>(<?php echo $terms[0]['term_title'];?>)</b></div> 



        </div>      

 



   <div>



    <div style="width: 80%;float: left;">



      <table width="100%" style="padding-right:3%;margin-top: 12px;margin-bottom: 14px;height: 84px;" cellspacing="0"  >  

   

   

      <tr>  

         <td width="15%" style="text-align:left;"> Student Name:   </td>

         <td width="35%" style="border-bottom: 1px solid black;text-align:center;">  <?php echo $std_data[$i]['name_cell'];  ?></td>



         <td width="15%" style="text-align:left;"> Father Name:   </td>

         <td width="35%" style="border-bottom: 1px solid black;text-align:center;">  <?php echo $std_data[$i]['last_name'];?></td>





      </tr>

   

      <tr>  

         <td width="15%" style="text-align:left;"> Class/Sec:   </td>

         <td width="35%" style="border-bottom: 1px solid black;text-align:center;"> 

         <?php echo $class[0]['Class_Name'];?> / <?php 



        $m->where("section_id", $std_data[$i]['section_id']);

        $sect=$m->get("edu_adm_section_detail");   echo $sect[0]['section_name'];?> </td>



         <td width="15%" style="text-align:left;"> Session:   </td>

          <td width="35%" style="border-bottom: 1px solid black;text-align:center;">

            <?php echo getSessionName($m,$terms[0]['session_id']);?> </td>







      </tr>

   

        <tr>  

         <td width="15%" style="text-align:left;"> Adm No:   </td>

         <td width="35%" style="border-bottom: 1px solid black;text-align:center;">  <?php echo $std_data[$i]['ref_no'];?></td> 



         <td width="15%">  Reg No:  </td>

         <td width="45%" style="border-bottom: 1px solid black;text-align:center;">  <?php echo $std_data[$i]['roll'];?> </td>





      </tr>

   

  

    

   

   </table>



    </div>





    <div style="width: 20%;float: left;background-color: white;">



      <?php if($std_data[$i]['img']!=NULL){ ?>

      

      <img src="<?php echo DOMAIN.AgentDirectory;?>students_pics/<?php echo $std_data[$i]['img'];?>" id="preview" class="img-thumbnail" style="margin-top: -38px;width: 144px;height: 131px; border: 2px solid black;"   />



       <?php }else { ?>   



           <img src="<?php echo DOMAIN.AgentDirectory;?>images/student_icon.PNG" id="preview"  class="img-thumbnail" style="margin-top: -38px;width: 144px;height: 131px; border: 2px solid black;"  />





       <?php } ?>



    </div>

   </div>



   <table width="100%" style="font-size:<?php echo $_REQUEST['font_size']."px";?>" cellspacing="0">  

   

   

         <tr style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">  

         

            <th width="8%"  class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">S.NO </th>

            <th width="31%"  class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;"> SUBJECTS </th>

            <?php if($_GET['total_marks']==1){?>

            <th width="12%"  class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;"> TOTAL  </th>

            <?php } ?>

            <?php if($_GET['obtained_marks']==1){?>

            <th width="12%"  class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">  OBTAINED  </th>

            <?php } ?>



            <th width="12%"  class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">  PERCENTAGE </th>

            <?php if($_GET['grade']==1){?>

            <th width="10%"  class="tdalign" style=" text-align:left;background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">Grade</th> 

            <?php } ?>

            

         </tr>

<?php 



          // printing all the relevant subjects of each class

                         

                         

          $qrr="SELECT csb.*,sb.* FROM eduportal_class_subjects as csb,eduportal_subject_config as sb WHERE csb.session_id=".$_REQUEST['session']." and csb.class_id=".$std_data[$i]['class_id']." and csb.section_id=".$std_data[$i]['section_id']." and csb.branch_id=".$_SESSION['branch']." and csb.subject_id=sb.subject_id order by csb.subject_order asc";



    

              $teacher_sbj = $m->query($qrr);

         

               $counter=1;

               $status;

               $remarksTeacher;

               

              foreach($teacher_sbj as $teacher_sb) {





                $m->where("subject_id", $teacher_sb['subject_id']);

                $subjects = $m->get("eduportal_subject_config"); 



                $m->where("branch_id", $_SESSION['branch']);

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

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

                $m->where("class_id", $std_data[$i]['class_id']);

                $m->where("section_id", $std_data[$i]['section_id']);

                $m->where("subject_id", $teacher_sb['subject_id']);

                $m->where("student_id", $std_data[$i]['student_id']);

                $marks = $m->get("eduportal_exam_marksheet"); 

              

              $total_marks+=$marks[0]['total_marks']+0;

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

             // $percentage = $total_obt*100/$total_marks;

              $percentage = ($marks[0]['obtained_marks']/$marks[0]['total_marks'])*100;

              



       

        

              if($marks[0]['obtained_marks']<=$marks[0]['total_marks'] || $marks[0]['obtained_marks']=="A" ){

                     

                     $grade = getGrade($percentage,$m); 



                }

        



               $display;

               if ($grade == "F") {

                  $status = 1;

                  //$remarksTeacher = 1;

                  $Failsub+=1;  

                 // $display="none";         

                 

               }//



               

               /*if ($marks[0]['obtained_marks']=="A") {

                 $display="none";

               }*/



               // skip row if total marks are not given of any subject



               if ($_GET['display_sub']=="No" && ($marks[0]['total_marks']==NULL || $marks[0]['total_marks']==0)){

                  continue;

               }



         

           ?>





           <?php if ($marks[0]['obtained_marks']!=NULL || $marks[0]['obtained_marks']!="" ) {?>

              

         <tr>  

         

            <td style="padding:<?php echo $_REQUEST['table_height']."%";?>"  class="tdalign"> <?php echo $counter; $counter++; ?> </td>

            <td   style="border:1px solid black; padding-left:3%;text-align:left;"> <?php echo $subjects[0]['subject']; ?> </td>

            <?php if($_GET['total_marks']==1){?> 

            <td  class="tdalign"> <?php echo $marks[0]['total_marks']; ?> </td>

            <?php } ?>



            <?php if($_GET['obtained_marks']==1){?>

            <td   class="tdalign" style="<?php if($grade=="F"){echo "background-color:#E26867;";}?>"> <?php echo $marks[0]['obtained_marks']; ?> </td>

            <?php } ?>



            <td  class="tdalign">

              <?php if($_GET['percantage']==1){?> 

             <?php if($marks[0]['obtained_marks'] !=NULL ){

             echo number_format(($marks[0]['obtained_marks']/$marks[0]['total_marks'])*100,1)."%";

              } } ?>

            </td>

            <?php if($_GET['grade']==1){?> 

            <td style="border: 1px solid black;text-align: center;"><?php  echo $grade; }?></td> 

                 

            

         </tr>





   <?php   }  } ?>



      <tr>  

         

            <th  colspan="2" style="text-align:right;font-weight:bold;border:1px solid black; background-color: 
            <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>; padding: <?php echo $tablePadding;?>;">TOTAL </th>



            <?php if($_GET['total_marks']==1){?> 

            <th   class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">
              <?php echo $std_data[$i]['total_marks']; ?> </th>

            <? } ?>



            <?php if($_GET['obtained_marks']==1){?>

            <th  class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">
              <?php echo $std_data[$i]['obt_marks'];?> </th>

            <?php } ?>

            <th  colspan="2" class="tdalign" style="background-color: <?php echo $_REQUEST['color'];?>;color:<?php echo $_REQUEST['font_color']?>;">

            <?php if($_GET['percantage']==1){?>

            <?php echo number_format($std_data[$i]['obt_marks']/$std_data[$i]['total_marks']*100,1)."%"; } ?> 

      </th>

         </tr>

  </table>

    <br>

       

     

     <table width="100%" style="font-size:<?php echo $_REQUEST['font_size']."px";?>" cellspacing="0">  

         <tr>  

         

           <td colspan="" style="text-align:center;border:1px solid black;padding:<?php echo $_REQUEST['table_height']."%";?>">

           <?php if($_GET['sec_pos']==1){?>

            <b>Position: </b> &nbsp;&nbsp;&nbsp;  <!-- <b>Out Of</b> --> 

            <?php  

              $postition=ordinal($count);





             if($std_data[$i]['obt_marks']==$std_data[$i-1]['obt_marks']){

                $postition=ordinal($count-1);



              }else {

                

                $count+=1;

              }    





                   echo $postition; 

} ?><!-- <span style="margin-left:40%;"> <?php echo count($std_data); ?></span> --> </td>

      

      <td style="text-align:center;border:1px solid black;padding:<?php echo $_REQUEST['table_height']."%";?>">

      <?php if($_GET['over_all']==1){?>

        <b>Grade:</b> 

      <?php 
            $avg=$std_data[$i]['obt_marks']/$std_data[$i]['total_marks']*100;

           $getGradeRemarks=explode(",",getGradeRemarks($avg,$m));

            $grade = $getGradeRemarks[0]; 


                  echo $grade;

           $status="";



           }  //print_r($getGradeRemarks);



               



            ?>

      </td>

   

      <td style="text-align:center;border:1px solid black;padding:<?php echo $_REQUEST['table_height']."%";?>; display: <?php echo $display;?>">

      <?php if($_GET['remarks']==1){?>

        <b>Remarks:</b>                

        

        <?php if ($remarksTeacher == 1){ echo "Fail"; } else { echo $getGradeRemarks[1]; } $remarksTeacher=""; $Failsub=0; $display="";  }?></td>

     

      <td style="text-align:center;border:1px solid black;padding:<?php echo $_REQUEST['table_height']."%";?>">

        <?php if($_GET['issuing_date']==1){?>

        <b>Result Date:</b> <?php echo date("d-M-Y",strtotime($_REQUEST['declaration_date'])); }?> 

         </td>

             

         </tr>



    <?php if($_GET['teacher_remarks']==1) { ?>

    <tr>  

        

      <td class="tdalign"style="padding:<?php echo $_REQUEST['table_height']."%";?>"><b>Teacher Remarks</b> </td>

      <td colspan="5" style="font-weight: bold; text-align:center;border:1px solid black;font-size:<?php echo $_REQUEST['font_size']."px";?>;"><?php echo $getGradeRemarks[2];?> </td>

    </tr>

    <?php } ?> 

   </table>



    <?php if ($_REQUEST['acadmicPerformance']=="Yes") { ?>



    <div   style="font-size:16px;text-align: center; width: 100%;font-weight: bold;"> Academic Performance </div>





 <table width="100%" style="font-size:<?php echo $_REQUEST['font_size']."px";?>; width:100%;" class="centertable" cellspacing="0">  

   

 

   <tr>  



        <th width="15%"  class="tdalign" style="font-size:<?php echo $_REQUEST['font_size']."px";?>" >Terms/Tests </th>



        <?php           

          foreach ($acadmic_heads as $acadmic_head) { ?>

          <th width="8%" class="tdalign" style="text-align:center;font-size:<?php echo $_REQUEST['font_size']."px";?>"> <?php echo $acadmic_head['heads_title'];?></th>

        <?php } ?>



     </tr>

  

 <?php 





          

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

    $m->where("branch_id", $_SESSION['branch']);

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

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

                 

    ?>

    

     <tr>  



        <th width="15%"  class="tdalign" style="font-size:<?php echo $_REQUEST['font_size']."px";?>" > <?php echo $TermTitles[0]['term_title'];?> </th>



        <?php   

                $NameOfTerm=$_REQUEST['term_id'];        

                foreach ($acadmic_heads as $acadmic_head1) {



                  $branID=$_SESSION['branch'];

                  $headID=$acadmic_head1['heads_id'];

                  $std_id=$std_data[$i]['student_id'];



                  $query7=" select * from eduportal_test_acadmic_performance_marks where branch_id='$branID' and heads_id='$headID' and term_id='$NameOfTerm' and student_id='$std_id'";

                 // print_r($query7);

                  $stdMarks = $m->query($query7);



                  $m->where("marks", $stdMarks[0]['student_remarks']);

                  $m->where("branch_id", $_SESSION['branch']);                  

                  $Remarks = $m->get("eduportal_performance_school_grades");

                

//print_r($query7);

               ?>



                <td class="tdalign"> <?php echo $Remarks[0]['remarks'] ?> </td>



              <?php } ?>



     </tr>



                   

    



       

            

                        





   </table>



 <?php } ?>

   

   <?php if ($_GET['attendance']=="Yes") { ?>

  



   <table  class="table table-striped table-bordered"style="width:100%; margin-top: 1%; float: left;font-size: <?php echo $_REQUEST['font_size']."px";?>">

                     



      <thead>

        <tr>

          <th colspan="5" style="border:1px solid black;border-bottom: none;">Summarize Attendance History (<?php echo date("d-M-Y",strtotime($_REQUEST['from']));?> - <?php echo date("d-M-Y",strtotime($_REQUEST['to']));?>)</th>

        </tr>



        <?php  $count5=1;



$branchID=$_SESSION['branch'];

$sessionIDs=$_SESSION['current_session'];

$STDid=$std_data[$i]['student_id']; 

$date=date('Y-m');

$from=$_REQUEST['from'];

$to=$_REQUEST['to'];



$qrp="SELECT count(*) as Present FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='P' and branch_Id='$branchID' ";

$qrp .= " AND (date BETWEEN '" .$from. "' AND '" .$to. "' )";

$Presents=$m->query($qrp);



$qra="SELECT count(*) as Absent FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='A' and branch_Id='$branchID' ";

$qra .= " AND (date BETWEEN '" .$from. "' AND '" .$to. "' )";



$Absents=$m->query($qra);



$qrl="SELECT count(*) as Leavestd FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='L' and branch_Id='$branchID' ";

$qrl .= " AND (date BETWEEN '" .$from. "' AND '" .$to. "' )";

//print_r($qrl);

$Leave=$m->query($qrl);



$qrsl="SELECT count(*) as ShortLeave FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='SL' and branch_Id='$branchID' ";

$qrsl .= " AND (date BETWEEN '" .$from. "' AND '" .$to. "' )";

$ShortLeave=$m->query($qrsl);



$qrla="SELECT count(*) as Late FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='LA' and branch_Id='$branchID' ";

$qrla .= " AND (date BETWEEN '" .$from. "' AND '" .$to. "' )";

$Late=$m->query($qrla);



?>

        <tr>

          

          <td width="20%" style="border:1px solid black;border-right: none;">Presents (<?php echo $Presents[0]['Present'];?>)</td>

          <td width="20%" style="border:1px solid black;border-right: none;">Absents (<?php echo $Absents[0]['Absent'];?>)</td>

          <td width="20%" style="border:1px solid black;border-right: none;">Leave (<?php echo $Leave[0]['Leavestd'];?>)</td>

          <td width="20%" style="border:1px solid black;border-right: none;">Short Leave (<?php echo $ShortLeave[0]['ShortLeave'];?>)</td>

          <td width="20%" style="border:1px solid black;">Late (<?php echo $Late[0]['Late'];?>)</td>

          

        </tr>

      </thead>

      <tbody>



                        



                        <!-- <tr>

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

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

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

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

                          <td style="border-right: 1px solid lightgray;text-align:center;"><?php echo $Late[0]['Late'];?></td>



                        </tr> -->



                      



                      </tbody>

                    </table>

                    <br><br><br>

  <?php } ?> 



  <!-- agrregate result -->



<?php if ($_GET['result_sumamry']=="Yes") { ?>



<div   style="font-size:16px;text-align: center; width: 100%;font-weight: bold;"> Result Summary </div>





<table width="100%" style="font-size:<?php echo $_REQUEST['font_size']."px";?>; width:100%;" class="centertable" cellspacing="0">  





<tr>  



<th width="15%"  class="tdalign" style="font-size:<?php echo $_REQUEST['font_size']."px";?>" >Terms/Tests </th>





<th width="8%" class="tdalign" style="text-align:center;font-size:<?php echo $_REQUEST['font_size']."px";?>"> Total Marks</th>



<th width="8%" class="tdalign" style="text-align:center;font-size:<?php echo $_REQUEST['font_size']."px";?>"> Obtained Marks</th>



<th width="8%" class="tdalign" style="text-align:center;font-size:<?php echo $_REQUEST['font_size']."px";?>"> Percentage</th>



<th width="8%" class="tdalign" style="text-align:center;font-size:<?php echo $_REQUEST['font_size']."px";?>"> Grade</th>





</tr>



<?php   



$totalTerm=0;

foreach ($_REQUEST['term_idChoose'] as $results) {



$totalTerm+=1;



$clsID=$_REQUEST['class_id'];

$secID=$_REQUEST['section'];

$bid=$_SESSION['branch'];

$Student_ID=$std_data[$i]['student_id']; 



/*$query=" select * from eduportal_exam_marksheet where class_id='$clsID' and section_id='$secID' and branch_id='$bid'";   

$result_summary = $m->query($query);*/



$m->where("term_id", $results);

$m->where("branch_id", $_SESSION['branch']);

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



/*if ($results['term_id']==$_REQUEST['term_id']) {

  continue;

}*/



if ($TermTitles[0]['term_title']==NULL) {

  continue;

}



$termID=$results;

$query1=" select SUM(total_marks) as TM, SUM(obtained_marks) as OB from eduportal_exam_marksheet where class_id='$clsID' and section_id='$secID' and branch_id='$bid' and student_id='$Student_ID' and term_id='$termID' and obtained_marks!=''"; 

//echo $query1;

$sumData = $m->query($query1);







/*if ($sumData[0]['obtained_marks']==NULL || $sumData[0]['obtained_marks']=="" ) {

continue;

}*/



$percentage=($sumData[0]['OB']/$sumData[0]['TM'])*100;





if ($totalTerm > 3) {

  continue;

}



  ?>



<tr>  



<td width="15%"  class="tdalign" style="font-size:<?php echo $_REQUEST['font_size']."px";?>" > <?php echo $TermTitles[0]['term_title'];?> </td>

<td class="tdalign"> <?php echo $sumData[0]['TM'] ?> </td>

<td class="tdalign"> <?php echo $sumData[0]['OB'] ?> </td>

<td class="tdalign"> <?php echo number_format(($sumData[0]['OB']/$sumData[0]['TM'])*100,1)."%";?> </td>

<td class="tdalign"> <?php echo getGrade($percentage,$m); ?> </td>



<?php } ?>



</tr>







</table>



<?php } ?>



   <!-- end aggrigate result -->

   <br><br><br><br><br>

  <?php if ($signatures[0]['result_card_instructions']!=NULL) { ?>

     <p><?php echo $signatures[0]['result_card_instructions'];?></p>

   <?php } ?>

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

   

   

         <tr>  

         <td  style="text-align:center;border-bottom:1px solid black;"> 



          <?php if($signatures[0]['teacher_exam_signature']!=NULL){ ?>

                        

            <img src="<?php echo DOMAIN;?>Production/signatures/<?php echo $signatures[0]['teacher_exam_signature'];?>" id="preview" class="img-thumbnail" style="width:130px;height:110px;"   />



         <?php } ?>



         </td>



         <td   >   </td>



         <td  style="text-align:center;border-bottom:1px solid black"> 



          <?php if($signatures[0]['principal_signature']!=NULL){ ?>

                        

            <img src="<?php echo DOMAIN;?>Production/signatures/<?php echo $signatures[0]['principal_signature'];?>" id="preview" class="img-thumbnail" style="width:130px;height:110px;"   />



         <?php } ?>



        </td>

         

         </tr>



         <tr>  

         <?php if ($signatures[0]['signature_type']=='Teacher') { ?>



           <td width="30%"  style="text-align:center;font-weight:bold;"> Teacher's Signature </td> 

         <?php } else { ?>



          <td width="30%"  style="text-align:center;font-weight:bold;"> Exam Controller Signature </td>



         <?php } ?> 

         <td width="30%"  style="text-align:center;">  </td> 

         <td width="30%"  style="text-align:center;font-weight:bold;">  Principal Signature </td> 



         

         </tr>



         <tr>  

            

            <td width="30%" colspan="3"  style="text-align:center;"> 



               <span style="font-size:12px;"><!--  Software Developed By: Aqib Majeed (Software Engineer) 03016138728  --> </span>

            

            </td> 

         

         </tr>





   </table>

 

    

</div>

  <br>

</page>

<br>

<?php

}



 $m->delete("eduportal_exam_temp_marks"); 



?>



</body>

</html>

