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

$m->where("user_id", $_SESSION['user_id']);
$m->where ("branch_id", $_SESSION['branch']);
$m->where("page_id", $_REQUEST['page']);
$access = $m->get("users_privilege_detail");


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

        $m->where("class_id", $_REQUEST['class_id']);  
     
      if($_REQUEST['session']!=NULL){

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

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

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

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

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

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


   }

        $m->where("term_id", $_REQUEST['term_id']);
        $terms = $m->get("eduportal_exam_terms");
 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>View MarkSheet | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   
  </head>
  <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>
  <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="view_marksheet.php">View Marksheets </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
         View Single Subject Marksheet
      
       <br><br>
      
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div >
      <form class="" action="view_Submarksheet.php" enctype="multipart/form-data" method="get">
        <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" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" name="session" />


<div class="pull-right">         

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


<?php 

 if(count($WorkAssignListings)>0){

?>

  <a target="_blank" title="Print Report" href="print_subject_marks.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&term_id=<?php echo $_GET['term_id'];?>&class_id=<?php echo $_GET['class_id'];?>&section=<?php echo $_GET['section'];?>&session=<?php echo $_GET['session'];?>&subjects=<?php echo $_GET['subjects'];?>" class="btn btn-primary">
    Print
  </a>


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

   <a  href="edit_marksheet.php?session=6b9l8m7l9vj17td7ubaa7uvo576b9l8m7l9vj17td7ubaa7uvo576b9l8m7l9vj17td7ubaa7uvo576b9l8m7l9vj17td7ubaa7uvo576b9l8m7l9vj17td7ubaa7uvo57&term_id=<?php echo $_GET['term_id'];?>&session=<?php echo $_GET['session'];?>&class_id=<?php echo $_GET['class_id'];?>&section=<?php echo $_GET['section'];?>&subjects=<?php echo $_GET['subjects'];?>&addaccountAdmin=1" target="_blank" class="btn btn-warning">
    Edit Marksheet
  </a>

  <?php } ?>


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

 <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?term_id=<?php echo $_REQUEST['term_id'];?>&session=<?php echo $_REQUEST['session'];?>&class_id=<?php echo $_REQUEST['class_id'];?>&section=<?php echo $_GET['section'];?>&subjects=<?php echo $_GET['subjects'];?>&action=DeleteTermSubjectMarks" onClick="return confirm('Are you sure you want to delete this records');"  class="btn btn-danger">Delete Marksheet </a>

<?php } ?>
   

<?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 col-xs-12" 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 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Term</label>

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

                    <?php
                    $m->where("session_id", $_SESSION['current_session']);
                    $m->where("branch_id", $_SESSION['branch']);
                    $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" 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($_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 col-xs-12" style="padding: 8px;" >
                <div class="form-group ">
                  <label class="required">Subjects</label>
                    <select name="subjects" id="subjects" class="form-control"  >
                      
                   <?php
                              if($_REQUEST['subjects']!='')
                              { 

                              
                              $section=$_REQUEST['section'];
                              $class=$_REQUEST['class_id'];
                              $sessionidid=$_REQUEST['session'];
  
                              $query="SELECT * FROM eduportal_subject_config as sub, eduportal_class_subjects as cls where cls.subject_id=sub.subject_id and cls.class_id='$class' and cls.section_id='$section' and cls.session_id='$sessionidid' ";


                              $secondLevel = $m->query($query);
                              
                              foreach($secondLevel as $secondLevel_val)
                              {
                              
                               ?>
                                <option <?php if($_REQUEST['subjects']==$secondLevel_val['subject_id']){echo "selected";} ?> value="<?php echo $secondLevel_val['subject_id']; ?>"><?php echo trim(utf8_encode_all($secondLevel_val['subject'])); ?></option>

                              <?php }  
                              
                               } ?>

                    </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="col-md-12">

                  <div  style="display:block;" class="alert alert-danger alert-dismissible">
                      <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                       <strong>Warning !</strong> Please select class and other parameters from advance search to view marksheet !!!
                  </div>



              </div>


<?php 

   }
?>   
     
        <div class="col-md-12">

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


<?php 

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

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

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

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

      }
?>
    <div style="overflow-x:auto;">


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

                    <th width="20%" style="text-align: center;border-color: white;"></th>
          
                </tr>

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



            


        </div>
  <?php  if(isset($_SESSION['yes'])){?>


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


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


<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="SendSingleSubjectSMS"  />
      <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_id"  value="<?php echo $_REQUEST['section']; ?>" >
      <input type="hidden" name="subjects"  value="<?php echo $_REQUEST['subjects']; ?>" >
      <input type="hidden" name="section"  value="<?php echo $WorkAssignListings[0]['section_id']; ?>" >
      <input type="hidden" name="limit"  value="<?php echo $brid[0]['sms_limit']; ?>" >

     <?php if(count($WorkAssignListings)>0  && $_REQUEST['section']!=NULL){  ?>

          
          
               
          
       
            <div class="col-md-2 pull-right" style="margin-top: 15px;">

             <input type="submit" name="submit" style="padding:3%;margin-top: -47px;" onClick=" return confirmation()" class="pull-right btn btn-primary"  value="SMS Short Result"  />
           </div>


        
              
      
         <?php 
            
          }
         
          ?>


 
    <table id="listofstudents1" data-page-length='100' class="table table-striped table-bordered" style="width:100%">
          
          <thead>
            <tr>
                <th width="3%">S.No</th>
                <th width="15%">Student Name</th>
                <th width="8%">Roll#</th>
                <th width="15%" style="text-align:center;"> Class </th>
                <th width="8%" style="text-align:center;"> Subject </th>
                <th width="5%" style="text-align:center;"> Total </th>
                <th width="5%" style="text-align:center;"> Obtained </th>
                <th width="4%" style="text-align:center;"> % </th>
                <th width="5%" style="text-align:center;"> Status </th>
                <th width="8%">

                <label class="container1">
                <input  type="checkbox" id="checkAll" /><span style="margin-top: -13px;" class="checkmark"></span>
                </label>
            
             </th>
                <!-- <th width="5%" style="text-align:center;"> Position </th> -->
                 
            </tr>
        </thead>
        <tbody>

     <?php $count=1;

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

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

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

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

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


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

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



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

//print_r($query);
         $average =  $m->query($query);
          
//echo $average[0]['grade_title']."<br>";
      ?>

        <tr>

        <input type="hidden" name="std_name<?php echo $WorkAssignListVal['student_id'];?>"  value="<?php echo $students[0]['first_name'] ?>" >
        <input type="hidden" name="tmarks<?php echo $WorkAssignListVal['student_id'];?>"  value="<?php echo $WorkAssignListVal['total_marks']; ?>" >
        <input type="hidden" name="obt<?php echo $WorkAssignListVal['student_id'];?>"  value="<?php echo $WorkAssignListVal['obtained_marks']; ?>" >
        <input type="hidden" name="numbers<?php echo $WorkAssignListVal['student_id'];?>"  value="<?php echo $students[0]['cell_no']; ?>" >
        <input type="hidden" name="subject"  value="<?php echo $subjects[0]['subject']; ?>" >
                  <td style="text-align:center;"> <?php echo $count; $count+=1;?> </td>
                  <td><?php echo $students[0]['first_name'];?></td>

                   <td> <?php 

                  
        if($_SESSION['branch']!=25){
         echo $students[0]['candidate_roll_no'];
       }else {
         echo $students[0]['ref_no'];
       }
       


                  ?> </td>

                  <td style="text-align:center;"> <?php echo $class[0]['Class_Name'];?> - <?php echo $section[0]['section_name'];?> </td>
                  <td style="text-align:center;"> <?php echo $subjects[0]['subject'];?> </td>
                  <td style="text-align:center;"> <?php echo $WorkAssignListVal['total_marks'];?> </td>
                  
                  <td style="text-align:center;"> <?php echo $WorkAssignListVal['obtained_marks'];?> </td>
                  <td style="text-align:center;"> <?php echo number_format($avg,2);?>% </td>

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

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

                  <?php } else {   ?>

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

                  <?php  } ?>
                  </td>

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


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

                 
              </tr>





              <?php
      } ?>



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

    <br><br>


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

           
          </div>
        </div>

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

  <!-- 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);}

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

      $("input:checkbox").prop('checked', $(this).prop("checked"));
  });
    </script>
  </body>
</html>
