<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php
$branch=$_SESSION['branch'];
 if($_REQUEST['class_id']!=NULL){

      $sql = "SELECT * FROM  edu_student_details  WHERE branch_id='$branch' and status='0'";

      if($_REQUEST['class_id']!=NULL){
      $sql .= " AND class_id ='" . $_REQUEST['class_id']. "' ";
      }

      if($_REQUEST['section']!=NULL){
      $sql .= " AND section_id ='" . $_REQUEST['section']. "' ";
     }

     if($_REQUEST['session']!=NULL){
      $sql .= " AND session_id ='" . $_REQUEST['session']. "' ";
     }

      if($_REQUEST['orderBy']=='asc'){
      $sql .= "order by first_name asc";
    }

      if($_REQUEST['orderBy']=='desc'){
      $sql .= "order by last_name asc";
    }

    if($_REQUEST['orderBy']=='RollNoWise'){
      $sql .= "ORDER BY CONVERT(SUBSTRING(candidate_roll_no,3),UNSIGNED) DESC";
      }

    if($_REQUEST['orderBy']=='AdmNoWise'){
        $sql .= "order by CAST(ref_no as unsigned)  asc";
      }

      //print_r($sql);
   $WorkAssignListings = $m->query($sql);
}
       $sessionIDs;
 
  if($_GET["session"]!=NULL ){

      $sessionIDs= $_GET["session"];
    }
    else{
      $sessionIDs= $_SESSION['current_session'];
    }
 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Add 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;">
           
<section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
      <form  action="add_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" />






          </span><div class="clearfix"></div> </div>
          <div class="panel-body">
          
            <div class="col-md-12" id="" >


                <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-2 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Term</label>
                  
                  <select name="term_id" id="term_id"  data-placeholder="Select" class="chosen-multi-select inputfield form-control" >
                    <option value="">Select Term</option>

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

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

                            <?php
                    } ?>

                </select> 

                  
                </div>
              </div> 

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

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

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

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


                            <?php
                    } ?>

                </select> 
                </div>
              </div>
              
              
              <div class="col-md-2 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Section</label>
                    <select name="section" id="txt_section" class="form-control" onChange="getSubjects(this.value)">
                      
                   <?php
                              if($_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'];
                              $sessionID=$_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='$sessionID' ";


                              $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-2 col-xs-12" style="padding: 8px;" >
                <div class="form-group ">
                  <label class="required">List Order By</label>
                     <select name="orderBy" id="orderBy" class="form-control" >
                      
                       <option <?php if($_REQUEST['orderBy']=='asc'){echo "Selected";}?> value="asc">Ascending Name</option>

                       <option <?php if($_REQUEST['orderBy']=='desc'){echo "Selected";}?> value="desc">Descending Name</option>

                       <option <?php if($_REQUEST['orderBy']=="AdmNoWise"){echo "Selected";}?>  value="AdmNoWise">Adm No Wise</option>

                       <option <?php if($_REQUEST['orderBy']=="RollNoWise"){echo "Selected";}?> value="RollNoWise">Roll No Wise</option>
                       
                       
                    </select>

                  
                </div>
            </div> 




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

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

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


            <div class="alert alert-danger" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Warning!</strong> Result already saved of this class, Please try another one.
            </div>


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

      

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

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

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

if(count($sub_mark)>0){ ?>

  <div style="color:black;font-size:18px;" class="alert alert-warning alert-dismissible">
  
  <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
      <strong>Alert !</strong> Warning! You have already save this marksheet to view <a href="view_Submarksheet.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&page=30&term_id=<?php echo $_REQUEST['term_id'];?>&class_id=<?php echo $_REQUEST['class_id'];?>&section=<?php echo $_REQUEST['section'];?>&session=<?php echo $_REQUEST['session'];?>&subjects=<?php echo $_REQUEST['subjects'];?>"><u>CLICK HERE</u></a>
  </div>

<?php } else { ?>

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


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

  <input type="hidden" id="class_id"  name="class_id" value="<?php echo $_GET['class_id']; ?>" />
  <input type="hidden" id="section_id"  name="section_id" value="<?php echo $_GET['section']; ?>" />
  <input type="hidden" id="term_id"  name="term_id" value="<?php echo $_GET['term_id']; ?>" />
  <input type="hidden" id="session"  name="session" value="<?php echo $_GET['session']; ?>" />
  <input type="hidden" id="subjects"  name="subjects" value="<?php echo $_GET['subjects']; ?>" />



<script>


function student_check(){

      
 
     var hello=document.getElementById("class_id").value;
     var hello1=document.getElementById("section_id").value;


         if(hello=="" || hello==null || hello1==null || hello1==null ){
          

          // $("#check_std_msg").slideDown('slow').delay(4000).slideUp('slow');
          document.getElementById("check_std_msg").style.display = "block";
          $("#check_std_msg").slideDown('slow').delay(5000).slideUp('slow');

        return false;
         }
    
        else {
          document.getElementById("check_std_msg").style.display = "none";
          return true;
         }
    
    
    

}

</script>



        <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>
    
          <?php  if(isset($_SESSION['error_msg'])){?>

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

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

        </div>

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

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

              <input type="submit" name="submit" class="pull-right btn btn-primary"  value="Save MarkSheet"  />


        </div>

  <?php } ?>

 
    <table data-page-length='100' class="table table-striped table-bordered" style="width:100%">
          
          <thead>
            <tr>
                <th width="3%">S.No</th>
                <th width="17%">Student Name</th>
                <th width="17%">Last Name</th>
                <th width="8%">Roll#</th>
                <th width="8%">Adm#</th>
                <th width="15%" style="text-align:center;"> Class </th>
                <th width="10%" style="text-align:center;"> Subject </th>
                <th width="10%" style="text-align:center;"> Total Marks 
                <input type="text" onkeyup="change_total(this.value);" id="total_marks" value="100" autocomplete="off" autofocus tabindex=1 required /> 


      <script>

       function change_total(value){

        
        var elements=document.getElementsByName("totalMarks[]");

        for(var i=0;i<elements.length; i++){
            
            //alert(elements[i].value);
            elements[i].value=value;
        
        }
      
      }

      </script>



     <script>

        function marks_check(value,row){
       // alert(value);
        var total=document.getElementById("totalMarks"+row).value;
       // alert(total);
       
        if(parseInt(value)>parseInt(total)){

          alert("value should not be greater");
          document.getElementById("obtmarks"+row).style.border = "1px solid red";

          document.getElementById("obtmarks"+row).value=null;



        } else {
          
        }

      
      }

      </script>


                </th>

                <th width="10%" style="text-align:center;"> Obtained </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']);
        $sessionID=$m->get("edu_session_config");
        $id=$WorkAssignListVal['student_id'];  
      ?>

        <tr>
          <td style="text-align:center;"> <?php echo $count; $count+=1;?> </td>
          <td>

             <input name="students[]" id="students[]" type="hidden" value="<?php echo $WorkAssignListVal['student_id'];?>">
             <?php echo $WorkAssignListVal['first_name'];?>

           </td>

          <td> <?php echo $WorkAssignListVal['last_name'];?> </td>
          <td><?php echo $WorkAssignListVal['candidate_roll_no'];?></td>
          <td><?php echo $WorkAssignListVal['ref_no'];?></td>

                  <td style="text-align:center;"> <?php echo $class[0]['Class_Name'];?> - <?php echo $section[0]['section_name'];?> </td>
                  <td> <?php //echo $WorkAssignListVal['candidate_roll_no'];?> </td>
                  <td> <input type="text" name="totalMarks[]" id="totalMarks<?php echo $id;?>" value="100"> </td>
                  
                  <td> <input type="text"  name="obtmarks[]" onkeyup="marks_check(this.value,<?php echo $id;?>);" id="obtmarks<?php echo $id;?>" autocomplete="off" tabindex=<?php echo $count; ?>    /> </td>
            
              </tr>





              <?php
      } ?>



           
            
           
        </tbody>
        
    </table>
 

</form>

<?php } ?>

</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);}
    </script>

  </body>
</html>
