<?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", 30);
$access = $m->get("users_privilege_detail");


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

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


<style type="text/css">

.right_col > div:nth-child(1) {
  padding:1%;  
  
}

.container1 {font-size: 13px;}

</style>


<script>
function showResult(str) {
  //alert(str);
  if (str.length==0) { 
    document.getElementById("livesearch").innerHTML="";
    document.getElementById("livesearch").style.border="0px";
    return;
  }
  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 (this.readyState==4 && this.status==200) {
      document.getElementById("livesearch").innerHTML=this.responseText;
      document.getElementById("livesearch").style.border="1px solid #A5ACB2";
      //alert(this.responseText);
    }
  }
  xmlhttp.open("GET","livesearch.php?q="+str,true);
  xmlhttp.send();
}


function StdMarksText(id)
    {
     alert(id);   
  
   var subarray=document.getElementsByName("sbmarks"+id+"[]");

   for (var i = 0; i < subarray.length; i++) { 

     subarray[i].removeAttribute('readonly'); 

   
   } 

    }


 /*   function StdMarksText(id){
      alert(id);
$("#text"+id).removeAttr('readonly');
}*/




function UpdateStudentMarks(count,id) {

 alert(count);
 // others fee parameters
 var termID=document.getElementById("term_id").value;
 var classID=document.getElementById("class_id").value;
 var sectionID=document.getElementById("txt_section").value;
 var sessionIDs=document.getElementById("session").value;


// general parameters to submit the fee
 var studentID=document.getElementById("stdId"+count).value;


 var marks = document.getElementsByName("sbmarks"+id+"[]");
// alert(mark);       
        var sum = 0;
       
        for (var i = 0; i < marks.length; i++) { 

                var mark = marks[i].value;

                alert(mark);

                                          
            
            }


//alert(termID);

    if (window.XMLHttpRequest) {
      xmlhttp=new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function() {

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

       if(xmlhttp.responseText=="1" || xmlhttp.responseText==1){
         
          document.getElementById("paynow"+count).style.display="none";
          document.getElementById("fullpaid"+count).style.display="block";
          document.getElementById("totalAmount_col"+count).value=collected;

         //alert(xmlhttp.responseText);
       }// ending main if condition 

      }

    }

  xmlhttp.open("GET","PayFullFee.php?action=PayChallan&collected="+collected+"&challan_id="+challan_id+"&fee_recv_sms="+fee_recv_sms+"&double_confirmation_sms_to_principal="+double_sms+"&student="+student+"&fine="+fine+"&std_name="+std_name+"&std_no="+std_no+"&Owner_no="+Owner_no+"&totalAmount="+totalAmount+"&paid_date="+date+"&month="+month+"&month_name="+month_name+"&PiadBy="+PiadBy,true);
 
  xmlhttp.send();

}
</script>

<!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 src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> -->

<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();
    }
                  
</script>
  </head>
  
  <body class="nav-md">
 


<!-- page content -->
  <div class="right_col" role="main">


    <div class="row">


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

          <a href="dashboard.php" target="_blank"   class="btn btn-success form-control">Admin Dashboard </a> 

          </div>
    
        <div class="col-md-2">

          <a href="basic_dashboard.php" target="_blank"   class="btn btn-success form-control">Staff Dashboard </a> 

        </div>
   

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

          <a href="add_marksheet.php" target="_blank"   class="btn btn-success form-control">Add Marksheet </a> 

          </div>
    
        <div class="col-md-2">

          <a href="examination.php" target="_blank"   class="btn btn-success form-control">View Marksheet </a> 

        </div>
   


      </div>



  <div class="" style="background-color: white;">
   
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
      
  <div class="panel panel-default">
    <div class="panel-heading">

    <span style="font-size: 16px;"> Students Result Reports </span>

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


<div class="pull-right">         


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

        
    <?php 

    $page;

    if($brid[0]['all_resultcards']!=NULL){
      $page=$brid[0]['all_resultcards'];
    }else{
      $page="print_all_reportcards1.php";  
    }

    ?>

            <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="page" value="<?php echo $page;?>" />
              <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; font-size:16px;"> Display Header</label>

                    <select name="header" class="form-control"> 
                       <option value="Yes">Yes</option>
                       <option value="No">No</option>
                    </select>
                 

                  <label class="container1" style="text-align: left; font-size:16px;"> Display Attendance</label>

                    <select name="attendance" class="form-control"> 
                       
                       <option value="No">No</option>
                       <option value="Yes">Yes</option>
                       
                    </select>



                  <label class="container1" style="text-align: left; font-size:16px;">Display Blank Subjects</label>

                    <select name="display_sub" class="form-control"> 
                       
                       <option value="No">No</option>
                       <option value="Yes">Yes</option>
                       
                    </select>


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

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

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

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

                  <label class="container1" style="text-align: left; font-size:16px;">
                    <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="PrintResultSheet">
             
                  <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;"> List Order </label>

                    <select name="order" class="form-control"> 
                       
                       <option value="position"> Position Wise </option>
                       <option value="Alpha">  Alphabetically  </option>
                       <option value="Rollno"> Roll No Wise </option>

                       
                    </select>
                  <br>
           

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

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="cell_no" checked value="1"/>
                    Cell Number
                    <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="reports.php" enctype="multipart/form-data" method="get">

<input type="hidden" name="page" value="<?php echo $_REQUEST['page'];?>" />

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

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

             <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 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']);
                    $m->orderBy("term_title","asc");
                    $WorkAssignList = $m->get("eduportal_exam_terms");
                    /*$query="select * from eduportal_exam_terms where branch_id=".$_SESSION['branch']." order by term_title asc ";
                    $WorkAssignList = $m->query($query);*/
                    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)">
                      
                      <option value="All"<?php if($_REQUEST['section']=="All"){echo "selected";} ?>>All</option>         
                   <?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 } ?>


                    </select>

                  
                </div>
              </div> 


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

                        
                        <?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-2 pull-left" style="padding:2px;" >
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 26px;float: left;">Search Results</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-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 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="">




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

     

       

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

          <div class="row">
          
        <div class="col-md-2" style="margin-bottom:1%;">
         <?php if($brid[0]['sms_service']=="0") { ?> 

          <input type="submit" name="detailed" style="padding:3%;"  onClick=" return confirmation()" class="pull-left btn btn-primary form-control"  value="SMS Subjectwise Result"  />
          <?php } else { ?>

          <input disabled type="submit" name="detailed" style="padding:3%;"  onClick=" return confirmation()" class="pull-left btn btn-primary  form-control"  value="SMS Subjectwise Result"  />

        <?php } ?>
       </div>
         
          
       <div class="col-md-2" style="margin-bottom:1%;">

            <?php if($brid[0]['sms_service']=="0") { ?> 

           <input type="submit" name="submit" style="padding:3%;" onClick=" return confirmation()" class="btn btn-primary  form-control"  value="SMS Short Result"  />

           <?php } else { ?>

            <input disabled type="submit" name="submit" style="padding:3%;" onClick=" return confirmation()" class="btn btn-primary  form-control"  value="SMS Short Result"  />

           <?php } ?>
            
         </div>


          <?php 

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

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

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

           </div>
           

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

          <a  data-toggle="modal" data-target="#PrintResultSheet"  href="#" class="btn btn-success  form-control">Print Result Sheet</a>
            
           </div>

          <?php 
             }
          ?>

       
      

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

            <?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'];?>&action=DeleteTermMarkSheet" style="margin-top: -2px;" onClick="return confirm('Are you sure you want to delete this records');"  class="btn btn-danger  form-control">Delete Marksheet </a> 

        <?php } ?>

        </div>


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

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

           <a href="add_marks.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'];?>&term_id=<?php echo $_GET['term_id'];?>" target="_blank"   class="btn btn-warning form-control">Edit Marksheet </a> 

         <?php } ?>

          </div>
         

         
      </div>
         

   <?php 
      
    }
   
    ?>    
       


    <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
         if($_REQUEST['class_id']!=NULL){  
     
             $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=".$WorkAssignListings[0]['section_id']." and csb.branch_id=".$_SESSION['branch']." and csb.subject_id=sb.subject_id";

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

          }

              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", $WorkAssignListings[0]['section_id']);
                $m->where("subject_id", $teacher_sb['subject_id']);

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

               //print_r($tmarks);
                ?>

                 <th width="6%" class="center"> <?php echo $subjects[0]['subject']."<br>".$tmarks[0]['total_marks']; ?> </th> 
                       
         <?php  $new_counter++;}  ?> 
   
               <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;"> Edit </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();

     // getting all the marks of students and other data
 
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
        $total_marks;
        $total_obt;
     
        // getting status of students marks


          $m->where("term_id", $_REQUEST['term_id']);
          $m->where("session_id", $_REQUEST['session']);
          $m->where("branch_id", $_SESSION['branch']);
          $m->where("student_id", $WorkAssignListVal['student_id']);
          $m->where("class_id", $_REQUEST['class_id']);
          $m->where("section_id", $WorkAssignListVal['section_id']);
          $sms_status = $m->get("eduportal_exam_marksheet");

           // print_r($sms_status);
          // 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";

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

             
              $sbs_marks="";
              $sbs_tmarks="";
              $sbs_title="";
              $sbs_msg1;

  
              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']);
                $m->where("class_id", $_REQUEST['class_id']);
                $m->where("section_id", $WorkAssignListVal['section_id']);
                $marks = $m->get("eduportal_exam_marksheet"); 

                $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 * 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['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;

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

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

  }// closing main loop    
    
    
  if($_REQUEST['class_id']!=NULL){  
     

   $query="select * from eduportal_exam_temp_marks where branch_id=".$_SESSION['branch']." order by percantage desc";
   $std_data=$m->query($query); 
  }
  // echo $query;

   //print_r($std_data);
   
   $position;
           
   $countRow=0;
   $count=0;
   for($i=0;$i<count($std_data);$i++){
     
     //print_r($data);

   ?>
      <input type="hidden" name="stdId" id="stdId<?php echo $count;?>" value="<?php echo $std_data[$i]['student_id'];  ?>">
       <tr>   
       

                  <td class=" center"> <?php echo $SR;  $SR++;?> </td>
                  <td style="padding-left:1%;"><?php echo $std_data[$i]['name_cell'];  ?></td>
                  <td class="center"> <?php echo $std_data[$i]['roll'];?> </td>
                  
                  <?php 
                   
                    $sbs1=explode(",",$std_data[$i]['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;"><input type="text" style="width:45px;" readonly name="sbmarks<?php echo $count;?>[]" onkeyup="total_sum(<?php echo $countRow;?>)" id="text<?php echo $count;?>" value="<?php  echo $sb1; ?>">  </td> 
                   <?php  $ii++;  } 
                   ?>
             
                  <td class=" center">  <?php echo $std_data[$i]['total_marks'];?>  </td>        
                  
                  <td class=" center">  <input type="text" style="width:45px;" name="totalOb<?php echo $count;?>[]" id="ob<?php echo $count;?>" value="<?php echo $std_data[$i]['obt_marks'];?>"> </td>
                  <td class=" center">  <?php echo number_format($std_data[$i]['percantage'],1);?>% </td>
                  <td class=" center" > <?php echo $std_data[$i]['grade'];?> </td>
                  <td class=" center" > <?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; 



          $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;" onclick="StdMarksText(<?php echo $countRow;?>)"  class="btn btn-success">Edit </a>

            <a style="padding: 0px 5px; font-size:14px;" onclick="UpdateStudentMarks(<?php echo $count;?>,<?php echo $countRow;?>)"  class="btn btn-success">Update </a>
          </td>

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

             <!-- Modal -->
            <div id="Modal<?php echo $std_data[$i]['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="StudentReportCard">
             
                  <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 $std_data[$i]['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 $WorkAssignListings[0]['section_id'];?>" />
                  <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="position" 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 -->

            </td>

            <script type="text/javascript">

                 function total_sum(id) {
        
        //alert(id);

        var marks = document.getElementsByName("sbmarks"+id+"[]");
        
        var sum = 0;
       
        for (var i = 0; i < marks.length; i++) { 

                var mark = marks[i].value;

                //alert(mark);

                total += Number(marks[i].value);

                sum += parseInt(marks[i].value);                           
            
            } 
//alert(total);
       
           document.getElementById("ob"+id).value=sum;

          
      }

              </script>

                  <td>

                  <?php 
                  $countRow++;
                   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=$std_data[$i]['student_id'];  ?> 


                    <input type="hidden" name="std_name<?php echo $uid; ?>"  value="<?php echo $std_data[$i]['name_cell']; ?>" >
                    <input type="hidden" name="student_id<?php echo $uid; ?>"  value="<?php echo $std_data[$i]['student_id']; ?>" >
                    <input type="hidden" name="grade<?php echo $uid; ?>"  value="<?php echo $average[0]['grade_title']; ?>" >
                    <input type="hidden" name="tmarks<?php echo $uid; ?>"  value="<?php echo $std_data[$i]['total_marks']; ?>" >
                    <input type="hidden" name="obt<?php echo $uid; ?>"  value="<?php echo $std_data[$i]['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 $std_data[$i]['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_exam_temp_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>
