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

<?php

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

$NameOfTerms=explode(",",$_REQUEST['terms']);

}
      
sort($NameOfTerms);
//$NumberOfTerms=count($NumberOf);

 $sessionIDs;

  if($_REQUEST['session']!=NULL){
    $sessionIDs=$_REQUEST['session'];
  }else { $sessionIDs=$_SESSION['current_session']; }

  if( $_REQUEST['section']!=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']!=NULL){

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

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


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


  }


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>Recent Results | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   
  </head>
  

<script type="text/javascript">
  
 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_sect.php?class_id="+id,true);

            xmlhttp.send();

          }




</script>

  <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; 
              
          Multi Test Report
          
          <br><br>

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



 <div >
      <form class="" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" enctype="multipart/form-data" method="post">
        <div class="panel panel-default">
          <div class="panel-heading"><?php echo count($WorkAssignListings);?> Students Records <span style="float:right;margin-top: -7px;">

        <input type="hidden" name="action"  value="SendTerm">

<div class="pull-right">         

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

  <?php 

 if($_REQUEST['class_id']!=NULL && $_REQUEST['section']!=NULL ){

?>

 <a target="_blank" style="padding: 10px;" title="Print Recent Result" class="btn btn-primary fa fa-print" href="print_recent_result.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&class_id=<?php echo $_GET['class_id'];?>&section=<?php echo $_GET['section'];?>&session=<?php echo $_GET['session'];?>&terms=<?php echo $_GET['terms'];?>&header=<?php echo $_GET['header'];?>">
    Print Report
  </a>

  <!-- <a target="_blank" style="padding: 10px;" title="Print Recent Result" class="btn btn-primary fa fa-print" href="print_all_multi_resultcard.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&class_id=<?php echo $_GET['class_id'];?>&section=<?php echo $_GET['section'];?>&session=<?php echo $_GET['session'];?>&terms=<?php echo $_GET['terms'];?>&header=<?php echo $_GET['header'];?>">
    Print Report Card
  </a> -->

  <a style="padding:7px; font-size:14px;" data-toggle="modal" data-target="#PrintMultiResultCard"; class="btn btn-primary fa fa-print"> Print Report Card </a>



<?php 
   }
?>

    

</div>

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

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

                        <?php

                        $WorkAssignList = $m->get("edu_session_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($sessionIDs==$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-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Class</label>
 

                  <select 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" 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($_REQUEST['section']!='')
                              { 

                             // $m->where("class_id", $_REQUEST['class_id']);    
                              $secondLevel = $m->get("edu_adm_section_detail");
                              
                              foreach($secondLevel as $secondLevel_val)
                              {
                              
                               ?>
                                <option <?php if($_REQUEST['section']==$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 } ?>

                    </select>

                  
                </div>
              </div> 

              <div class="col-md-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Show Branch Name/Logo</label>
                    <select name="header" id="" class="form-control">
                   
                   <option <?php if($_REQUEST['header']=="Yes"){echo "Selected";} ?> value="Yes">Yes</option>
                   <option <?php if($_REQUEST['header']=="No"){echo "Selected";} ?> value="No">No</option>

                    </select>

                  
                </div>
              </div> 

            <!--   <div class="col-md-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Number Of Test</label>
 

                 <select name="number" id="number" class="form-control"> 

                  <?php for ($num=1; $num<21; $num++){ echo '<option>' .$num. '</option>'; } ?>

                   </select>


                </div>
              </div> -->


           <div class="col-md-1" 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>

              <table>
                
              <div class="col-md-12">
             
               <?php 
                    
                    $m->where("session_id", $sessionIDs);
                    $m->where("branch_id", $_SESSION['branch']);
                    $m->orderBy("term_title","asc");
                    $WorkAssignList = $m->get("eduportal_exam_terms");

                  foreach($WorkAssignList as $WorkAssignListVal) { ?>
                   <tr>
                <div class="col-md-2" >
                  <div class="form-group" > 
                  <label class="container1">
                    <input type="checkbox" name="terms[]" checked value="<?php echo $WorkAssignListVal['term_id'];?>" />
                    <span style="font-size:12px;"><?php echo " ".$WorkAssignListVal['term_title'];?></span> <span class="checkmark"></span>
                  </label>
                  <?php } ?>
                  </div>
                </div>
              </tr>
            </div>
            
              </table>
            </div>
            <div class="clearfix"></div>
          </div>
        </div>
      </form>
      <div class="clearfix"></div>
    </div>
    <br>



      <div id="PrintMultiResultCard" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header" style="border-bottom:none;">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title" style="text-align:center;"> Choose Parameters  </h4>
            </div>

            <div class="modal-body">

<script type="text/javascript">

  function HideDateABC(str){
  
  if(str=="YES"){
    
    document.getElementById("gradeID").style.display="block";
    document.getElementById("subNo").style.display="block";
   
  }
  else {
    
    document.getElementById("gradeID").style.display="none";
    document.getElementById("subNo").style.display="none";
   
   
  }
}


</script>


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

           <input type="hidden" name="action" value="PrintAllMultiReportCards"> 
           <input type="hidden" id="date"  name="class_id" value="<?php echo $_GET['class_id']; ?>" />
           <input type="hidden" name="section" value="<?php echo $_GET['section']; ?>">
           <input type="hidden" name="session" value="<?php echo $_GET['session']; ?>">
           <input type="hidden" name="terms" value="<?php echo $_GET['terms']; ?>">
           <input type="hidden" name="header" value="<?php echo $_GET['header']; ?>">
           
<div class="col-md-12" style="padding: 8px;">


      <div class="form-group ">

    <label class="">Print Format</label>
        <select  name="printFormat" class="form-control"  >
          <option value='blankpage'>On Blank Page</option>
          <option value='letterhead'>On Letter Head</option>     
          <option value='custom_header'>Custom School header</option>               

        </select>
      </div>

      <div class="form-group ">

    <label class="">Display Acadmic Performance</label>
        <select  name="acadmicPerformance" class="form-control"  >

          <option value='YES'>YES</option>
          <option value='NO'>NO</option>                   

        </select>
      </div>

      <div class="form-group ">

    <label class="">Display Attendance</label>
        <select  name="attendance" class="form-control"  >

          <option value='NO'>NO</option>
          <option value='YES'>YES</option>                             

        </select>
      </div>


      <div class="form-group ">

    <label class="">Display Result Card Instructions</label>
        <select  name="result_card_instructions" class="form-control"  >

          <option value='NO'>NO</option>
          <option value='YES'>YES</option>                             

        </select>
      </div>

       <div class="form-group ">

    <label class="">Hide Positions</label>
        <select  name="hide_positins" class="form-control"  >

          <option value='NO'>NO</option>
          <option value='YES'>YES</option>                             

        </select>
      </div>


      <div class="form-group ">

      <label class="">Table Height</label>
      <select name="table_height" class="form-control"> 

      <option value=".1">1%</option>
      <option value=".2">2%</option>
      <option value=".3">3%</option>
      <option value=".4">4%</option>
      <option value=".5">5%</option>
      <option value=".6">6%</option>
      <option value=".7">7%</option>
      <option value=".8" selected>8%</option>
      <option value=".9">9%</option>
      <option value="1">10%</option>
      <option value="1.1">11%</option>
      <option value="1.2">12%</option>
      <option value="1.3">13%</option>
      <option value="1.4">14%</option>
      <option value="1.5">15%</option>
      <option value="1.6">16%</option>

      </select>
      </div>



      <div class="form-group col-md-4 ">

    <label onChange="HideDateABC(this.value);" class="">Display Pass/Fail</label>
        <select  name="displayPassFail" class="form-control"  >
          <option value='NO'>NO</option>
          <option value='YES'>YES</option> 
          
        </select>
      </div>


<div class="form-group col-md-4" id="gradeID" >

<label class="">Choose Grade</label>
<select name="pick_grade" class="form-control" >
     

<?php


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

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


<?php
} ?>

</select>
</div>


<div class="form-group col-md-4" id="subNo">

<label class="">Number Of Subjects</label>
<select name="sub_no" class="form-control" >
     
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>

</select>
</div>

       
</div> 
                                
                  
                                       
      
            <div class="modal-footer">

            <button type="submit" class="btn btn-primary" name="submit" >Submit </button>
              


            </div>



                 </form>

          </div>

          </div>

        </div>
      </div>

      <!-- Student result popup ending -->
     
          
          <?php  if(!isset($_REQUEST['section'])){?>


        <div class="alert alert-warning" id="msg" style="color:black;font-size:16px;font-weight: bold;">
             <a href="#" class="close" data-dismiss="alert"   aria-label="close">&times;</a>
              <strong>Warning!</strong> Please select class and section to view results !!!
            </div>



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

      

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

          
           <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>
    
         </div>



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

<?php 

$m->where("term_id", $_REQUEST['term_id']);
$m->where("branch_id", $_SESSION['branch']);
$terms = $m->get("eduportal_exam_terms");
?>
  
      <input type="hidden" name="action" 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 $_REQUEST['section']; ?>" >
      <input type="hidden" name="limit"  value="<?php echo $brid[0]['sms_limit']; ?>" >

     

        <div class="col-md-3" style="margin-bottom:1%;">

         <?php 
         
          if(count($WorkAssignListings)>0){
            ?>

          <!-- <input type="submit" name="submit" onClick=" return confirmation()" class="pull-right"  value="Send Result To Parents"  /> -->



         <?php 
            
          }
         
          ?>    
             

        </div>


 <strong> <h3 style="float:left;"> Multi Test Reports </h3> </strong>
    
    <table id="listofstudents" data-page-length='10' class="table table-striped table-bordered" style="width:100%;font-size:11px;">
          
          <thead>
            <tr>
                <th width="2%">S.No</th>
                <th width="10%">Name</th>
                <th width="5%">R.NO</th>

 <?php 
    $sessionIDs=$_REQUEST['session'];
    foreach ($NameOfTerms as $NameOfTerm) {
      
      $m->where("term_id", $NameOfTerm);
      $m->where("branch_id", $_SESSION['branch']);
        $m->where("session_id", $sessionIDs);
        $TermTitles = $m->get("eduportal_exam_terms");

       // echo $TermTitles[0]['term_title'];
       

         $b=$_SESSION['branch'];
         $trm=$TermTitles[0]['term_id'];
         $clas=$_REQUEST['class_id'];
         
         $query="select SUM(obtained_marks)as obt,SUM(total_marks) as tm from eduportal_exam_marksheet where branch_id='$b' AND term_id='$trm' AND class_id='$clas'";
               
         $marks = $m->query($query);

         

         if($marks[0]['obt']!=NULL){
          $avg=0+$marks[0]['obt']/$marks[0]['tm']*100;
         }else {
          $avg=0;
         }
        
        // break loop if terms printing three times

          if($marks[0]['obt']==NULL){
           continue;
          }
          else{
            
            $count++; 
          }


  
      ?>          
             <th width="8%" style="text-align:center;"> <?php echo $TermTitles[0]['term_title']; ?> </th> 
             
             <?php }  ?> 

               <th width="8%" style="text-align:center;"> Total Aggregate </th>  
               <th width="8%" style="text-align:center;"> Positions </th> 
               
            
                 
            </tr>
        </thead>
        <tbody>
  
     
     <?php 
     $counter=1;
     $total_marks=0;
     
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
        
        $total_obt;
     

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

        
      ?>

        <tr>
          

<?php $marking=0;

    

     $percentages="";
     $sessionIDs=$_REQUEST['session'];
    foreach ($NameOfTerms as $term_s) {
      
        $m->where("term_id", $term_s);
        $m->where("branch_id", $_SESSION['branch']);
        $m->where("session_id", $sessionID);
        $TermId = $m->get("eduportal_exam_terms");

     
       $b=$_SESSION['branch'];
       $student_id=$WorkAssignListVal['student_id'];
       $secID=$_REQUEST['section'];

       $query="select SUM(obtained_marks)as obt,SUM(total_marks) as tm from eduportal_exam_marksheet where branch_id='$b' AND term_id='$term_s' AND student_id='$student_id' AND section_id='$secID' AND class_id=".$_REQUEST['class_id'];
     //  echo $query;
       $marks = $m->query($query);
      //print_r($marks);

        if(count($marks)>0){

         // $avg=0+($marks[0]['obt']/$marks[0]['tm'])*100;
          $obtainmarks=$marks[0]['obt'];
          $totalmarks=$marks[0]['tm'];
      
       //   echo $obtainmarks." / ".$totalmarks."<br>";
       //   $avg=0+intVal($obtainmarks)/intVal($totalmarks)*100;
            $avg=0+number_format($marks[0]['obt']*100 / $marks[0]['tm'],2);
           // echo $avg."<br>";
          $percentages=$percentages.",".$avg;

        } else {
          $avg=0;
        }
        
        
        if($marks[0]['tm']==NULL){
         continue;
        }
              

        $total_marks=$total_marks+$avg;
         

      ?>          
    
   
   <?php  }
   // now calculating aggregate

    $aggregate=($count*100);


   $new_array['name_cell']=$students[0]['first_name']." ".$students[0]['last_name'];
   $new_array['roll']=$students[0]['candidate_roll_no'];
   $new_array['percantage']=$percentages;
   $new_array['total_aggregate']=($total_marks/$aggregate)*100;
   $new_array['branch_id']=$_SESSION['branch'];
           
   $m->insert("eduportal_multi_test_positions_temp",$new_array); 

   $percentages="";
   $test="";

    ?> 

<?php $total_marks=0; 

}

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

   $query="select * from eduportal_multi_test_positions_temp where branch_id=".$_SESSION['branch']."  GROUP by pos_temp_id order by AVG(total_aggregate) desc";

  // echo $query;

   $std_data=$m->query($query); 
  }
 //  echo $query;

  // print_r($std_data);
   
   $position;
             
  $count=1;
  $Serial=1;


  for($i=0;$i<count($std_data);$i++){
     
   
   ?>
                  <td style="text-align: center;"> <?php echo $Serial; ?> </td>
                  <td style=""><?php echo $std_data[$i]['name_cell'];  ?></td>
                  <td style=""><?php echo $std_data[$i]['roll'];  ?></td>
                 
                   <?php 
                   
                    $sbs1=explode(",",$std_data[$i]['percantage']);
                   //print_r($sbs1);
                   //echo print_r(array_reverse($sbs))."="; 
                    //$sbs1=array_reverse($sbs1);
                    $condition=count($sbs1);
                    $ii=0;
                  foreach($sbs1 as $sb1) { 

                    if($sb1==NULL || $sb1==""){
                      continue;
                    }

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

                  <td width="8%" style="text-align:center;"> <?php  echo number_format($sb1,2); ?> % </td> 
                   <?php  $ii++;  } 
                   ?>


                  <td style="text-align:center;"><?php echo number_format($std_data[$i]['total_aggregate'],1);  ?> %</td>

                   <td style="text-align: center;"> <?php 

                   $postition=ordinal($count);


                   if($std_data[$i]['total_aggregate']==$std_data[$i-1]['total_aggregate']){
                      $postition=ordinal($count-1);

                    }else {
                      
                      $count+=1;
                    }    


                         echo $postition; 

                   ?> 


                   </td>
       
              </tr>
              

  <?php  $Serial++;
 
      } 

       $m->delete("eduportal_multi_test_positions_temp"); 
      ?>

   
        </tbody>
        
    </table>
  
</form>


    <br><br>


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

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

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
