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

ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
ini_set('max_execution_time', '0'); // for infinite time of execution 

$branch=$_SESSION['branch'];
$term=$_REQUEST['term_id'];
$session=$_REQUEST['session'];
$section=$_REQUEST['section'];
$class=$_REQUEST['class_id'];



 if($_REQUEST['class_id']!=NULL){  
  
      $qrr = "SELECT * FROM  eduportal_exam_marksheet  WHERE branch_id='$branch' and term_id='$term' and session_id='$session' and class_id='$class' and section_id='$section' group by student_id";
//print_r($qrr);
      $WorkAssignListings = $m->query($qrr);

  }


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

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

        $m->where("session_id", $_REQUEST['session']);
        $session=$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 lang="en">
  <head>
    
    <title>Result Reports | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   <link href="<?php echo DOMAIN;?>Production/css/select2.min.css" type="text/css" rel="stylesheet">
   <link href="<?php echo DOMAIN;?>Production/css/bootstrap-select.min.css" type="text/css" rel="stylesheet">

   <!-- files for multiselect dropdown -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>  
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css" />

<script>
      

        function getSubjects(id){
            
            var session=document.getElementById("session").value;
            var clas=document.getElementById("class_id").value;
            
            if (window.XMLHttpRequest) {

              // code for IE7+, Firefox, Chrome, Opera, Safari

              xmlhttp=new XMLHttpRequest();

            } else { // code for IE6, IE5

              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange=function() {

              if (xmlhttp.readyState==4 && xmlhttp.status==200) {

                document.getElementById("subjects").innerHTML=xmlhttp.responseText;
                //alert(xmlhttp.responseText);

              }

            }

            xmlhttp.open("GET","get_subjects.php?section="+id+"&class="+clas+"&session="+session,true);

            xmlhttp.send();




          }
                        



  function getsec(id){

      if (window.XMLHttpRequest) {

        // code for IE7+, Firefox, Chrome, Opera, Safari

        xmlhttp=new XMLHttpRequest();

      } else { // code for IE6, IE5

        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

      }

      xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4 && xmlhttp.status==200) {

          document.getElementById("txt_section").innerHTML=xmlhttp.responseText;
          // alert(xmlhttp.responseText);

        }

      }

      xmlhttp.open("GET","get_section_all.php?class_id="+id,true);

      xmlhttp.send();




    }
                  



    function show_message(){
      
      $("#msg").slideDown('slow').delay(4000).slideUp('slow');
      $("#error").slideDown('slow').delay(5000).slideUp('slow');

     

    }

</script>
<script type="text/javascript">
  
function getterm(id){
//alert(id);
            if (window.XMLHttpRequest) {

              // code for IE7+, Firefox, Chrome, Opera, Safari

              xmlhttp=new XMLHttpRequest();

            } else { // code for IE6, IE5

              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange=function() {

              if (xmlhttp.readyState==4 && xmlhttp.status==200) {

                document.getElementById("term_id").innerHTML=xmlhttp.responseText;
               //  alert(xmlhttp.responseText);

              }

            }

            xmlhttp.open("GET","get_term.php?session_id="+id,true);

            xmlhttp.send();

          }

</script>
  </head>
  




  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">
          <div class="" style="background-color: white;">
   
         <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
         <a href="examination.php">View Marksheets </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
          Old Test Report
          <br><br>

        
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div >
      
        <div class="panel panel-default">
          <div class="panel-heading">

          <input type="hidden" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" name="session" />


<div class="pull-right">         


  <?php 

 if($_REQUEST['class_id']!=NULL && $WorkAssignListings[0]['section_id']!=NULL ){

?>

 <!-- <a  data-toggle="modal" data-target="#PrintAll"  href="#" class="btn btn-primary">Print All Result Cards</a> -->



  <a  data-toggle="modal" data-target="#PrintResultSheet"  href="#" class="btn btn-primary">Print Result Sheet</a>

<?php 
   }
?>


  <a onClick="$('#advanceSearch').toggle('blind')" class="btn btn-primary" style="cursor:pointer;">Advance Search</a>

  <a  href="old_test_results.php" class="btn btn-primary"> Multi Old Test Results</a>




 <!-- Modal -->
            <div id="PrintAll" class="modal fade" role="dialog">
              <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                   
               <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

                  <input type="hidden" name="action" value="StudentAllReportCard">
             
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title"> Choose The Parameters To Display in <strong> Result Cards </strong>  </h4>
                  </div>
                  <div class="modal-body">
                  
                  <input type="hidden" name="term_id" value="<?php echo $_REQUEST['term_id'];?>" />
                  <input type="hidden" name="session" value="<?php echo $_REQUEST['session'];?>" />
                  <input type="hidden" name="class_id" value="<?php echo $_REQUEST['class_id'];?>" />
                  <input type="hidden" name="section" value="<?php echo $_REQUEST['section'];?>" />
                  <input type="hidden" name="pos" value="<?php echo $postition;?>" />
                  <input type="hidden" name="out_of" value="<?php echo count($WorkAssignListings);?>" />

                            
                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="percantage" checked value="1"/>
                    Percentage
                    <span class="checkmark"></span>
                  </label>
                  
                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="grade" checked value="1"/>
                    Grade
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="sec_pos" checked value="1"/>
                    Position
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="over_all" checked value="1"/>
                    Overall Grade
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="remarks" checked value="1"/>
                    Remarks
                    <span class="checkmark"></span>
                  </label>
             
                <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="issuing_date" checked value="1"/>
                    Issuing Date
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="teacher_remarks" checked value="1"/>
                    Teacher Remarks
                    <span class="checkmark"></span>
                  </label>

                  </div>
                  <div class="modal-footer" style="text-align: right;">
                    <input type="submit" class="btn btn-primary" checked value="Print" />
                  </div>


                   </form>
                </div>

              </div>
            </div>
            <!-- Modal -->

            
    <!-- Modal -->
            <div id="PrintResultSheet" class="modal fade" role="dialog">
              <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                   
               <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

                  <input type="hidden" name="action" value="PrintOldResultSheet">
             
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title"> Choose The Parameters To Display in <strong> Result Sheet </strong>  </h4>
                  </div>
                  <div class="modal-body">
                  
                  <input type="hidden" name="term_id" value="<?php echo $_REQUEST['term_id'];?>" />
                  <input type="hidden" name="session" value="<?php echo $_REQUEST['session'];?>" />
                  <input type="hidden" name="class_id" value="<?php echo $_REQUEST['class_id'];?>" />
                  <input type="hidden" name="section" value="<?php echo $_REQUEST['section'];?>" />
                  <input type="hidden" name="pos" value="<?php echo $postition;?>" />
                  <input type="hidden" name="out_of" value="<?php echo count($WorkAssignListings);?>" />

                            
                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="rollno" checked value="1"/>
                    Roll No
                    <span class="checkmark"></span>
                  </label>
                  
                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="obtained" checked value="1"/>
                    Obtained
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="percentage" checked value="1"/>
                    Percentage
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="grade" checked value="1"/>
                    Grade
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="position" checked value="1"/>
                    Position
                    <span class="checkmark"></span>
                  </label>
             
                  </div>
                  <div class="modal-footer" style="text-align: right;">
                    <input type="submit" class="btn btn-primary" checked value="Print" />
                  </div>


                   </form>
                </div>

              </div>
            </div>
            <!-- Modal -->

</div>

<form  action="old_results.php" enctype="multipart/form-data" method="get">

          </span><div class="clearfix"></div> </div>
          <div class="panel-body">

            <div class="col-md-12" id="advanceSearch" style="display:none;">


              <div class="col-md-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Session</label>
                    <select name="session" id="session" class="form-control" onChange="getterm(this.value)" >

                              <option value="">Select Session</option>
                        

                        <?php
 
 
 
                      $match;
                      if(!isset($_REQUEST['session'])){
                        $match=$_SESSION['current_session'];
                      }else { $match=$_REQUEST['session']; }
                     
   
                        $WorkAssignList = $m->get("edu_session_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($match==$WorkAssignListVal['session_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['session_id']; ?>"><?php echo $WorkAssignListVal['session_year']; ?></option>


                                <?php
                        } ?>

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

             <div class="col-md-3" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Term</label>

                  <select name="term_id" id="term_id"  data-placeholder="Select" class="chosen-multi-select inputfield form-control" >
                    <option value="">Select Term</option>

                    <?php
                   // $m->where("session_id", $_SESSION['current_session']);
                    $m->where("branch_id", $_SESSION['branch']);
                    $m->orderBy("term_title","asc");                    
                    $WorkAssignList = $m->get("eduportal_exam_terms");
                    foreach($WorkAssignList as $WorkAssignListVal)
                    { ?>

                       <option <?php if($_REQUEST['term_id']==$WorkAssignListVal['term_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['term_id']; ?>"><?php echo $WorkAssignListVal['term_title']; ?></option>


                            <?php
                    } ?>

                </select> 

                  
                </div>
              </div> 
              
      

             <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Class</label>
 

                  <select  data-placeholder="Select" class="chosen-multi-select inputfield form-control" name="class_id" id="class_id" class="form-control" onChange="getsec(this.value)"  >
                    <option value="">Select Class</option>

                    <?php
                    $m->where("branch_id", $_SESSION['branch']);
                    $WorkAssignList = $m->get("edu_class_config");
                    foreach($WorkAssignList as $WorkAssignListVal)
                    { ?>

                       <option <?php if($_REQUEST['class_id']==$WorkAssignListVal['class_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['class_id']; ?>"><?php echo $WorkAssignListVal['Class_Name']; ?></option>


                            <?php
                    } ?>

                </select> 
                </div>
              </div>
              
              
              <div class="col-md-2 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Section</label>
                    <select name="section" id="txt_section" class="form-control" onChange="getSubjects(this.value)">
                              
                   <?php
                              if($WorkAssignListings[0]['section_id']!='')
                              { 

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

                              $secondLevel = $m->get("edu_adm_section_detail");
                              
                              foreach($secondLevel as $secondLevel_val)
                              {
                              
                               ?>
                                <option <?php if($WorkAssignListings[0]['section_id']==$secondLevel_val['section_id']){echo "selected";} ?> value="<?php echo $secondLevel_val['section_id']; ?>"><?php echo trim(utf8_encode_all($secondLevel_val['section_name'])); ?></option>

                              <?php }   ?>
                                
                          <?php } ?>

                          <option value="All"<?php if($_REQUEST['section']=="All"){echo "selected";} ?>>All</option>

                    </select>

                  
                </div>
              </div> 


           <div class="col-md-3 pull-right" style="padding:2px;" >
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 24px;float: right;">Search</button>
                </div>
              </div>

             
            </div>
            <div class="clearfix"></div>
          </div>
        </div>
      </form>
      <div class="clearfix"></div>
    </div>
    <br>

     
          
          <?php  if(!isset($_REQUEST['class_id'])){?>


            <div class="alert alert-danger" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Warning!</strong> Please select class and section to view result !!!
            </div>


          <?php  unset($_SESSION['error']); }?>

      

          
          <?php  if(isset($_SESSION['msg_sent'])){?>


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Messages sent successfully...
            </div>


          <?php  unset($_SESSION['msg_sent']);
           }?>

      
<div style="">


        <div class="col-md-8">

          
           <div id="check_std_msg" style="display:none;" class="alert alert-warning alert-dismissible">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                     <strong>Warning !</strong> Please select class to save marksheet !!!
            </div>
    
          <?php  if(isset($_SESSION['error_msg'])){?>

           <div id="error"  class="alert alert-warning alert-dismissible">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                     <strong>Warning !</strong> You have already saved the attendance of this class !!!
            </div>

         <?php  unset($_SESSION['error_msg']); }?>

        </div>



<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

  
      <input type="hidden" name="action_call" value="SendResultSMS"  />
      <input type="hidden" name="term_title"  value="<?php echo $terms[0]['term_title']; ?>" >
      <input type="hidden" name="term_id"  value="<?php echo $_REQUEST['term_id']; ?>" >
      <input type="hidden" name="session"  value="<?php echo $_REQUEST['session']; ?>" >
      <input type="hidden" name="class_id"  value="<?php echo $_REQUEST['class_id']; ?>" >
      <input type="hidden" name="section"  value="<?php echo $WorkAssignListings[0]['section_id']; ?>" >
      <input type="hidden" name="limit"  value="<?php echo $brid[0]['sms_limit']; ?>" >

   

    <table class="table table-bordered"  style="width:100%;font-size:10px;">
          
          <thead>
            <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="2%" class=" center">  </th>  

<?php 
                $new_counter=0;
              // printing all the relevant subjects of each class
            $branch=$_SESSION['branch'];
            $term=$_REQUEST['term_id'];
            $session=$_REQUEST['session'];
            $section=$_REQUEST['section'];
            $class=$_REQUEST['class_id'];

              $qrr1 = "SELECT * FROM  eduportal_exam_marksheet  WHERE branch_id='$branch' and term_id='$term' and session_id='$session' and class_id='$class' and section_id='$section' group by subject_id";

             //print_r($qrr1);
            $teacher_sbj = $m->query($qrr1);

              foreach($teacher_sbj as $teacher_sb) {

               
                $m->where("subject_id", $teacher_sb['subject_id']);
                $subjects = $m->get("eduportal_subject_config");
   
  
                // getting subject total marks

                $m->where("branch_id", $_SESSION['branch']);
                $m->where("term_id", $_REQUEST['term_id']);
                $m->where("session_id", $_REQUEST['session']);
                $m->where("class_id", $_REQUEST['class_id']);
                $m->where("section_id", $_REQUEST['section']);
                $m->where("subject_id", $teacher_sb['subject_id']);
                $tmarks = $m->get("eduportal_exam_marksheet"); 

               
                ?>

                 <th width="6%" class="center"> <?php echo $subjects[0]['subject']."<br>".$tmarks[0]['total_marks']; ?> </th> 
                       
         <?php  }  ?> 
   
               <th width="8%" class=" center"> Total </th>  
               <th width="8%" class=" center"> Obtained </th>  
               <th width="8%" class=" center"> % </th>  
               <th width="8%" class=" center" > Grade </th>  
              <!--  <th width="5%" class=" center"> Position </th>  --> 
               <th width="5%" style="text-align:center;"> Report </th>  
               <th width="5%" style="text-align:center;"> SMS </th>  
  
            <!--   <th width="8%">

            <label class="container1">
              <input  type="checkbox" id="checkAll" /><span style="margin-top: -13px;" class="checkmark"></span>
            </label>
            
             </th> -->

            </tr>
        </thead>
        <tbody>


   
     
       
     <?php 
     $count=1;
     $SR=1;
     $new_array = array();

   
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
        $total_marks;
        $total_obt;
     
                 
        
          $m->where("branch_id", $_SESSION['branch']);
          $m->where("student_id", $WorkAssignListVal['student_id']);
          $studentsDetails = $m->get("edu_student_details");

          // printing all the relevant subjects of each class
          
             $StdId=$WorkAssignListVal['student_id'];

          $qrr2 = "SELECT * FROM  eduportal_exam_marksheet  WHERE branch_id='$branch' and term_id='$term' and session_id='$session' and class_id='$class' and section_id='$section' group by subject_id";
          
         // print_r($qrr);
          $teacher_sbj = $m->query($qrr2);
                     
              $sbs_marks="";
              $sbs_tmarks="";
              $sbs_title="";
              $sbs_msg1;


              $student_marks;
  
              foreach($teacher_sbj as $teacher_sb) {

                $m->where("term_id", $_REQUEST['term_id']);
                $m->where("session_id", $_REQUEST['session']);
                $m->where("subject_id", $teacher_sb['subject_id']);
                $m->where("branch_id", $_SESSION['branch']);
                $m->where("student_id", $WorkAssignListVal['student_id']);
                $marks = $m->get("eduportal_exam_marksheet"); 
//print_r($marks);
                $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, 3, "UTF-8")." ".$marks[0]['obtained_marks']."/".$marks[0]['total_marks'];
                  $sbs_msg1=$val.",".$sbs_msg1;              
    
                  }


                /*$sbs_tmarks=$marks[0]['total_marks'].",".$sbs_tmarks;              
                $sbs_title=substr($teacher_sb['subject'],0,2).",".$sbs_title;              */
              
                } // closing subjects marks loop
              

             $avg=($total_obt/$total_marks)*100;
             $avg=$avg+0;
             // getting average of total marks
             $query="SELECT grade_id,grade_title FROM eduportal_exam_school_grades WHERE percantage_start_range <=".round($avg)." and percantage_end_range >=".round($avg)." and branch_id=".$_SESSION['branch'];
           
            //echo $query."===".$WorkAssignListVal['first_name']."====".$avg."<br><br>";            

             $average =  $m->query($query);
        
               $new_array['first_name']=$studentsDetails[0]['first_name'];
               $new_array['candidate_roll_no']=$studentsDetails[0]['candidate_roll_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_status']=$sms_status[0]['sms_status'];
               $new_array['student_id']=$studentsDetails[0]['student_id'];
               $new_array['cell_no']=$studentsDetails[0]['cell_no'];
               $new_array['sbs_total']=$sbs_msg1;

        
        
            //  print_r($new_array)."<br><br>";            
              // $m->insert("eduportal_old_exam_marks",$new_array); 

              // $response_data = json_encode($new_array);

              //echo  "<pre>".print_r($response_data)."</pre>"; 
              //  echo  $response_data;

                $student_marks[]=$new_array;
  

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

  }// closing main loop    


    
// check duplicate records 

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

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

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

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

    $termRecord=$m->get('eduportal_old_exam_marks_json');


    if(count($termRecord)>0){

        //  continue;

        } else {
    

    $response_data = array(
      'term_id' => $_REQUEST['term_id'],
      'session_id' => $_REQUEST['session'],
      'class_id' => $_REQUEST['class_id'],
      'section_id' => $_REQUEST['section'],
      'students_marks' => json_encode($student_marks)
    );
     
    $m->insert ('eduportal_old_exam_marks_json', $response_data);

    }


 

   $termID=$_REQUEST['term_id'];
   $sessionIDs=$_REQUEST['session'];
   $classID=$_REQUEST['class_id'];
   $sectionID=$_REQUEST['section'];   

   $resultset = $m->query("select * from eduportal_old_exam_marks_json where term_id='$termID' and session_id='$sessionIDs' and class_id='$classID' and section_id='$sectionID'");

 
  $StudentsMarks=json_decode($resultset[0]['students_marks'], true);

   foreach($StudentsMarks as list("grade" => $grade, "cell_no" => $cell_no, "session" => $session, "branch_id" => $branch_id, "obt_marks" => $obt_marks, "sbs_total" => $sbs_total, "sub_marks" => $sub_marks, "first_name" => $first_name, "percantage" => $percantage, "sms_status" => $sms_status, "student_id" => $student_id, "total_marks" => $total_marks, "candidate_roll_no" => $candidate_roll_no ) ) { 
     
 // echo "{$sub_marks}"."<br>";
//echo "<pre>"; print_r($datastd); echo "</pre>";
  //  echo "<br>page";

    $m->where("student_id", $student_id);
    $studentName=$m->get("edu_student_details");

   ?>

       <tr>   
       

                  <td class=" center"> <?php echo $SR;  $SR++;?> </td>
                  <td style="padding-left:1%;"><?php echo $studentName[0]['first_name'];  ?></td>
                  <td class="center"> <?php echo $candidate_roll_no;?> </td>
                  
                  <?php 
                   
                    $sbs1=explode(",",$sub_marks);
                   
                   //echo print_r(array_reverse($sbs))."="; 
                    $sbs1=array_reverse($sbs1);
                    $condition=count($sbs1);
                    $ii=0;
                  foreach($sbs1 as $sb1) { 

                    /*if($ii==$condition){break;}*/
                    ?>

                  <td width="8%" style="text-align:center;"> <?php  echo $sb1; ?> </td> 
                   <?php  $ii++;  } 
                   ?>
             
                  <td class=" center">  <?php echo $total_marks;?>  </td>                  
                  <td class=" center">  <?php echo $obt_marks;?> </td>
                  <td class=" center">  <?php echo number_format($percantage,1);?>% </td>
                  <td class=" center" > <?php echo $grade;?> </td>
                  <!-- <td class=" center" > <?php 

             $postition=ordinal($count);


             if($obt_marks==$obt_marks-1){
                $postition=ordinal($count-1);

              }else {
                
                $count+=1;
              }    


                   echo $postition; 



          $sms=$std_data[$i]['name_cell']." (".$class[0]['Class_Name']."-".trim($terms[0]['term_title']).") ".$std_data[$i]['sbs_total']." TM:".$std_data[$i]['obt_marks']."/".$std_data[$i]['total_marks']." Position:".$postition."
          ".$brid[0]['msg_name'];   
              // echo $sms."<br>";

                   ?> 


                   </td> -->
</form>
          

           <td> <a style="padding: 0px 5px; font-size:14px;" data-toggle="modal" data-target="#Modal<?php echo $student_id;?>"  href="#" class="btn btn-success">
                  Print </a>

             <!-- Modal -->
            <div id="Modal<?php echo $student_id;?>" class="modal fade" role="dialog">
              <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">

                   
               <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

                  <input type="hidden" name="action" value="StudentOldReportCard">
             
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title"> Choose The Parametter To Display Print Report </h4>
                  </div>
                  <div class="modal-body">
                  <!-- <label class="container1">Check All<input  type="checkbox" class="checkAll"/><span class="checkmark"></span></label> -->
                           
                  <input type="hidden" name="student_id" value="<?php echo $student_id;?>" />
                  <input type="hidden" name="term_id" value="<?php echo $_REQUEST['term_id'];?>" />
                  <input type="hidden" name="session" value="<?php echo $_REQUEST['session'];?>" />
                  <input type="hidden" name="class_id" value="<?php echo $_REQUEST['class_id'];?>" />
                  <input type="hidden" name="section" value="<?php echo $_REQUEST['section'];?>" />
                  <input type="hidden" name="pos" value="<?php echo $postition;?>" />
                  <input type="hidden" name="out_of" value="<?php echo count($WorkAssignListings);?>" />

                 <!-- <label style="text-align: left;"> <b>Sub Heading:</b>
                    <input type="text" style="width: 470px;" name="studnetlist" value="Student List"/>
                 </label> -->
               
                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="percantage" checked value="1"/>
                    Percentage
                    <span class="checkmark"></span>
                  </label>
                  
                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="grade" checked value="1"/>
                    Grade
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="out_of" checked value="1"/>
                    Out Of
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="over_all" checked value="1"/>
                    Overall Grade
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="remarks" checked value="1"/>
                    Remarks
                    <span class="checkmark"></span>
                  </label>
             
                <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="issuing_date" checked value="1"/>
                    Issuing Date
                    <span class="checkmark"></span>
                  </label>

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="teacher_remarks" checked value="1"/>
                    Teacher Remarks
                    <span class="checkmark"></span>
                  </label>

                  </div>
                  <div class="modal-footer" style="text-align: right;">
                    <input type="submit" class="btn btn-primary" checked value="Print" />
                  </div>


                   </form>
                </div>

              </div>
            </div>
            <!-- Modal -->

            </td>

                  <td>

                  <?php 
                   if($std_data[$i]['sms']==1){ ?>

                    <a data-toggle="modal" data-target="#payChallan1<?php echo $WorkAssignListVal['student_id'];?>" target="_blank" style="padding: 0px 5px; font-size:14px;"  class="btn btn-success">  Sent </a>

                  <?php }else { ?> 



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

                  <?php } $uid=$student_id;  ?> 


                    <input type="hidden" name="std_name<?php echo $uid; ?>"  value="<?php echo $studentName[0]['first_name']; ?>" >
                    <input type="hidden" name="student_id<?php echo $uid; ?>"  value="<?php echo $student_id; ?>" >
                    <input type="hidden" name="grade<?php echo $uid; ?>"  value="<?php echo $grade; ?>" >
                    <input type="hidden" name="tmarks<?php echo $uid; ?>"  value="<?php echo $total_marks; ?>" >
                    <input type="hidden" name="obt<?php echo $uid; ?>"  value="<?php echo $obt_marks; ?>" >
                    <input type="hidden" name="pos<?php echo $uid; ?>"  value="<?php echo $postition; ?>" >
                    <input type="hidden" name="numbers<?php echo $uid; ?>"  value="<?php echo $cell_no; ?>" >
                    <input type="hidden" name="msg_txt<?php echo $uid; ?>"  value="<?php echo $sms; ?>" >



                   </td>
                  <!--  <td>
                   <label class="container1">
                   <input type="checkbox" name="checkboxes[]"  value="<?php echo $std_data[$i]['student_id']; ?>"  class="cb-element" /><span class="checkmark"></span>
                  </label>
                  </td> -->
                                 
              </tr>



              <?php $total_marks=0; $total_obt=0;   ?>




              <?php
      } 

     // $m->delete("eduportal_old_exam_marks"); 

      ?>

        </tbody>
        
    </table>

  
 


</div>

<br><br>


  </div>
  <div class="clearfix"></div>
</section>          
    

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

<script>
$("#subuser").click(function(){
    $("#sub_user_form").show();
    $("#table_sub_agent").hide();
  });
  $("#back").click(function(){
    $("#sub_user_form").hide();
    $("#table_sub_agent").show();
  });
</script>

   <script>

        $(document).ready(function() {
          $('#listofstudents').DataTable();
           $("th").removeClass("sorting");
          } 
        );

        $("#checkAll").change(function () {

            $("input:checkbox").prop('checked', $(this).prop("checked"));
        });


    </script>
       <!-- jQuery -->
    <script src="js/ajax_functions.js"></script>  
    
  <?php include('RootMe/js_linksscript.php');?>


    <!-- searchable dropdown -->
    
    <link href="autosearch_select/select2.css" rel="stylesheet">
    <link href="autosearch_select/select2-default.css" rel="stylesheet">
    <script src="autosearch_select/select2.min.js"></script>
    
    <script>
    $(function() {
    $('.chosen-select').select2( { width:'100%', maximumSelectionSize: 1 } );
    $(document).ready(function() {
    $(".chosen-multi-select").select2( { width:'100%', } ); }); }); function slideout(){ setTimeout(function(){
    $(".alert-success").fadeOut("slow", function () { });
    $(".alert-danger").fadeOut("slow", function () { }); }, 4000);}
    </script>

  </body>
</html>
