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

<?php

// delete checked students 

    if(isset($_POST['Delete'])){

     // print_r($_POST['students']);

      foreach($_POST['students'] as $stds){

          $data = array('status' => '1');
          $m->where("branch_id", $_SESSION['branch']);
          $m->where("student_id", $stds);

          $result =  $m->update ('edu_student_details', $data);
   
      }
   
      header("location:manage_students.php?".session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&section=".$_POST['section']);


 }
   
    $session;

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

          $session=$_REQUEST['session'];
          
        }else {
          
          $session=$_SESSION['current_session'];
        }

       $branch=$_SESSION['branch'];
       
       $classes = $m->query("select * from edu_class_config where branch_id=".$branch." order by class_id asc limit 1");
       // print_r($classes);
       


     /* code for advance Search*/


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

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

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

    }

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



  if(isset($_REQUEST['from']) && isset($_REQUEST['to']) && $_REQUEST['fee']==1){
    

    
      if($_REQUEST['from']!=" " && $_REQUEST['from']!=NULL ) {
        $from=date("Y-m-d",strtotime($_REQUEST['from']));  

      }else {
        $from=date("01-m-Y");  
      }
     
      if($_REQUEST['to']!=" " && $_REQUEST['to']!=NULL   ) {
        $to=date("Y-m-d",strtotime($_REQUEST['to']));
      }else {
        $to=date("t-m-Y");  
      } 
      
    
    $sql .= " AND entrance_date BETWEEN '" .$from. "' AND '" .$to. "'";
  }

 // echo $sql;

  $WorkAssignListings = $m->query($sql);
} else {

  $sql = "SELECT * FROM  edu_student_details  WHERE branch_id='$branch' and status='0' and session_id='$session' ";
 $WorkAssignListings = $m->query($sql); 
}

 ?>

<!DOCTYPE html>
<html lang="en">
  <head>
   
    <title> View Students | EduPortal </title>
     <?php include('RootMe/css_links.php');?> 
  </head>
  
<script type="text/javascript">

  function HideDate(str){
  
  if(str=="1"){
    
    document.getElementById("from").style.display="block";
    
    document.getElementById("col1").style.display="block";
    document.getElementById("col2").style.display="block";
  }
  else {
    
    document.getElementById("from").style.display="none";
  
    document.getElementById("col1").style.display="none";
    document.getElementById("col2").style.display="none";
  }
}



</script>

<script>

  function HideDate1(str){
  
  if(str=="1"){
    
    document.getElementById("from").style.display="block";
    document.getElementById("to").style.display="block";
    document.getElementById("col1").style.display="block";
    document.getElementById("col2").style.display="block";
  }
  else {
    
    document.getElementById("from").style.display="none";
    document.getElementById("to").style.display="none";
    document.getElementById("col1").style.display="none";
    document.getElementById("col2").style.display="none";
  }
}

</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="row" 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"><?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;float: right;">Advance Search</a>

<?php 

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

?>

  <a title="Print Students List" data-toggle="modal" data-target="#StudentsPrintModal"  href="#" class="fa fa-print btn btn-primary" style="padding: 10px;">&nbsp;Print List
    
  </a>

<?php 

   }
?>

</div>






            <!-- Modal -->
            <div id="StudentsPrintModal" 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="ClassPrintParameter">
             
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title"> Choose The Parametters To Display in 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="class_id" value="<?php echo $_GET['class_id'];?>" />
                  <input type="hidden" name="section" value="<?php echo $_GET['section'];?>" />
                  <input type="hidden" name="from" value="<?php echo $_GET['from'];?>" />
                  <input type="hidden" name="to" value="<?php echo $_GET['to'];?>" />
                  <input type="hidden" name="session" value="<?php echo $_SESSION['current_session'];?>" />
                 
                 <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="admission" checked value="1"/>
                    Admission
                    <span class="checkmark"></span>
                  </label>
                  
                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="student_name" checked value="1"/>
                    Student Name
                    <span class="checkmark"></span>
                  </label>

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

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

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

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

                  <label class="container1" style="text-align: left;">
                    <input type="checkbox" name="tution_fee" checked value="1"/>
                    Tution Fee
                    <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 -->










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






          </span><div class="clearfix"></div> </div>
          <div class="panel-body">
          
            <div class="col-md-12" id="advanceSearch" style="display:none;">
            
              <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Class</label>

            
                    <select name="class_id" onChange="getsec(this.value)" class="form-control" >
                     <option value="All">All</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-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Section</label>
                    <select name="section" id="txt_section" class="form-control" >
                      
                   <?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-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Session</label>
                    <select name="session" class="form-control" >

                    <!-- <option value="">All</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">Admission Status</label>
                              <select name="fee" onChange="HideDate1(this.value);" class="form-control"  >

                                <option value='All'>All</option>
                          
                                <option <?php if($_GET['fee']=="1"){echo 'selected';}?> value='1'>Search By Joining Date</option>
                                                       

                                  
                              </select>
                            </div>


                </div>


                <div class="col-md-3 col-xs-12" style="padding:8px;<?php if(isset($_REQUEST['from']) && isset($_REQUEST['to']) && $_REQUEST['fee']==1){ echo 'display:block;';}else {echo 'display:none;';} ?>"  id="col1">

                       <div class="form-group ">

                          <label class="required"> From Date</label>
                              <input name="from"  id="from" value="<?php echo $_GET['from'];?>" type="date" class="form-control"  >
                       
                          </div>
                  </div>                     
             

                  <div class="col-md-3 col-xs-12" style="padding:8px;<?php if(isset($_REQUEST['from']) && isset($_REQUEST['to']) && $_REQUEST['fee']==1){ echo 'display:block;';}else {echo 'display:none;';} ?>"  id="col2">

                       <div class="form-group ">

                          <label class="required"> To Date</label>
                              <input name="to" id="to" value="<?php echo $_GET['to'];?>" type="date" class="form-control"  >
                       
                          </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="float: right;">Search</button>
                </div>
              </div>

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

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


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Student record is added successfully...
            </div>
          <?php  unset($_SESSION['addsuccess']); }?>

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


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Student has been re-enrolled successfully...
            </div>
          <?php  unset($_SESSION['reEnroll']); }?>



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


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


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

 

<form action="manage_students.php" enctype="multipart/form-data" method="post">


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


<div style="">

<table id="listofstudents" class="table table-striped table-bordered" style="width:100%">
  <input onClick="return confirm('Are you sure you want to delete selected students ?');" class="btn btn-primary pull-right" type="submit" name="Delete" value=" Checked Delete Students">
        <thead>
            <tr>

              
                <th width="5%">  S.No</th>
                <th width="20%"> Student Name</th>
                <th width="7%">  Roll#</th>
                <th width="10%"> Cell </th>
                <th width="18%"> Class </th>
                <th width="10%"> Manage Fee </th>
                <th width="8%">  Action </th>
                <th width="3%">  Profile</th>

                <th width="5%">

              <label class="container1"><input  type="checkbox" id="checkAll"/><span class="checkmark" style="margin-top: -17px;"></span></label>
              
               </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']);
        $session=$m->get("edu_session_config");
        
      ?>

        <tr>

          <td style="text-align:center; padding: 2px;"><?php echo $count++;?></td>        

                  <td style="padding: 2px;" > 

<!-- making a link   -->

<a style="padding: 0px 5px; font-size:14px;"  href="student_profile.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&class_id=<?php echo $_REQUEST['class_id']; ?>&section=<?php echo $_REQUEST['section']; ?>&session=<?php echo $_REQUEST['session']; ?>&student=<?php echo $WorkAssignListVal['student_id']; ?>" style="cursor:pointer;">


                  <?php if($WorkAssignListVal['image']!=NULL){?>

                    <img style="border-radius:50%;height:30px;width:30px;" src="<?php echo DOMAIN.AgentDirectory;?>/students_pics/<?php echo $WorkAssignListVal['image'];?>"  />
                  <?php }else {?>

                    <img style="border-radius:50%;height:30px;with:30px;" src="images/student.png" />

                  <?php }?>
                  
                   &nbsp;&nbsp; <?php echo $WorkAssignListVal['first_name'];?>
</a>
                   
                   
</td>

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

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


                  ?> </td>
                  <td style="text-align:center; padding: 2px;"> <?php echo $WorkAssignListVal['cell_no'];?> </td>
                  <td style="text-align:center; padding: 2px;">
                   <?php echo getClassName($m,$WorkAssignListVal['class_id']);?>
                   ( <?php echo getSectionName($m,$WorkAssignListVal['section_id']);?>) </td>
                  
                   <td style="text-align:center; padding: 2px;"> 

                  <a style="padding: 0px 5px; font-size:14px;"  href="create_student_fee.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&student=<?php echo $WorkAssignListVal['student_id'];?>#table_sub_agent" style="cursor:pointer;"  class="btn btn-success">

                  Manage
                  </a>

                  </td>


                <td style="padding: 2px;">

            <a style="padding: 0px 5px; font-size:14px;"  href="edit_student.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&student=<?php echo $WorkAssignListVal['student_id'];?>#sec" style="cursor:pointer;"  class="btn btn-success">

            <i class="fa fa-pencil" aria-hidden="true"></i>


            </a>




      <a style="padding: 0px 5px; font-size:14px;" data-toggle="modal" data-target="#EmpPayroll<?php echo $WorkAssignListVal['student_id'];?>,<?php echo $_SESSION['branch'];?>"; class="btn btn-danger"><i class="fa fa-remove"></i> </a>
          
                  </td>

      <!-- Student Result popup start -->


      <div id="EmpPayroll<?php echo $WorkAssignListVal['student_id'];?>" 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;"> Reasons of Delete (<?php echo $WorkAssignListVal['first_name']." - ".$WorkAssignListVal[0]['user_lname']; ?>)  </h4>
            </div>

            <div class="modal-body">

</form>


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

           <input type="hidden" name="action" value="delete_student"> 
           <input type="hidden" id="date"  name="month" value="<?php echo $_GET['month']; ?>" />
           <input type="hidden" name="session" value="<?php echo $student[0]['session_id']; ?>">
           <input type="hidden" name="branch" value="<?php echo $student[0]['branch_id']; ?>">
           <input type="hidden" name="student" value="<?php echo $WorkAssignListVal['student_id']; ?>">
           
                   <div class="col-md-12" style="padding: 8px;">

                       <div class="form-group ">

                          <label class="required">Reasons</label>
                              <select required name="fee" onChange="HideDate(this.value);" class="form-control"  >

                                <option value=''>Select</option>
                                <option <?php if($_GET['fee']=="0"){echo 'selected';}?> value='Completed'>Class/Course Completed</option>
                                <option <?php if($_GET['fee']=="0"){echo 'selected';}?> value='Migration'>Migration </option>
                                <option <?php if($_GET['fee']=="0"){echo 'selected';}?> value='Miss Behaviour'>Miss Behaviour</option>
                                <option <?php if($_GET['fee']=="0"){echo 'selected';}?> value='Fee Defaulter'>Fee Defaulter</option>
                                 <option <?php if($_GET['fee']=="0"){echo 'selected';}?> value='Regular Absents'>Regular Absents</option>
                                                                 
                                <option <?php if($_GET['fee']=="1"){echo 'selected';}?> value='1'>Other </option>
                                  
                              </select>
                            </div>


                    </div> 
                   
              
                  
                  <div class="col-md-12" style="padding:8px;<?php if(isset($_REQUEST['from']) && $_REQUEST['fee']==1){ echo 'display:block;';}else {echo 'display:none;';} ?>"  id="col1">

                       <div class="form-group ">

                          <label class="required"> Explain</label>
                              <textarea name="expln"  id="from" value="<?php echo $_POST['expln']?>" type="text" class="form-control"></textarea>
                       
                          </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 -->



    <td style="padding: 2px;">


<a style="padding: 0px 5px; font-size:14px;"  href="student_profile.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&class_id=<?php echo $_REQUEST['class_id']; ?>&section=<?php echo $_REQUEST['section']; ?>&session=<?php echo $_REQUEST['session']; ?>&student=<?php echo $WorkAssignListVal['student_id']; ?>" style="cursor:pointer;"  class="btn btn-success">

      PROFILE
</a>




      </td>

<td style="padding: 2px;">
      <label class="container1">
  <input type="checkbox" name="students[]" value="<?php echo $WorkAssignListVal['student_id'];?>"><span class="checkmark"></span>
      </label>
</td>


              </tr>





              <?php
      } ?>
 
        </tbody>
        
    </table>

  </div>

    </form>

    <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');?> 
  <!-- Links for Datatable-->

<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
 <script>
        
  $(document).ready(function() {
    $('#listofstudents').DataTable({
      "pageLength": 100
    });
    } 
  );

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

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


</script>
  
  </body>
</html>
