<?php
include_once 'header.php';

?>

<div class="page-wrapper">
        <!-- ============================================================== -->
        <!-- Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->
        <div class="page-breadcrumb">
          <div class="row">
            <div class="col-12 d-flex no-block align-items-center">
              <h4 class="page-title">All Assign Course List for Student </h4>
              <div class="ms-auto text-end">
                <nav aria-label="breadcrumb">
                  <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="#">Dashboard</a></li>
                    <li class="breadcrumb-item active" aria-current="page">
                     Student
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">
                    <a href="#" id="add">Assign Course</a>
                    </li>
                  </ol>
                </nav>
              </div>
            </div>
          </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Bread crumb and right sidebar toggle -->
     
        <div class="container-fluid row">
            <div class="col-12">  
              <div class="card">
                <div class="card-body">
                  <h5 class="card-title"> </h5>
                  <div class="table-responsive">
                    <table id="zero_config" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>S.No</th>
                          <th>Batch No</th>
                          <th>Course Name</th>
                          <th>Shift Time</th>
                          <th>Status</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                        
                              <?php
                                
                                $obj=new Database();
                                $id='';
                                if(isset($_POST['s_id']))
                                {
                                    $id=" student_id=".$_POST['s_id'];                                 
                                   
                                }
                                else{
                                   $id=null;
                                }
                                $obj->select('students_course','*',null,$id,'id DESC',null);
                                $result=$obj->getResult(); 
                                $c=0;
                                                              
                                foreach($result as list("f_id"=>$id,"batch_no"=>$batch_no,"course_name"=>$course_name,"shift_time"=>$shift_time,"status"=>$status))
                                {
                            
                                  $c=$c+1;
                                  echo "<tr><td>$c</td><td class='id'><a href='#'>$batch_no</a></td><td>$course_name</td><td>$shift_time</td><td>$status</td><td><button class='badge btn-info btn-edit' name='edit[]' data-id=$id id='edit'><span class='mdi-tooltip-edit'></span></button>&nbsp;&nbsp;<button class='badge btn-danger' name='id[]' data-id=$id id='id'>X</button></td></tr>";
                                }
                              
                                ?>
                      </tbody>
                  
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- ============================================================== -->
          <!-- End PAge Content -->
          <!-- ============================================================== -->
          <!-- ============================================================== -->
<div class="modal" id="myModal1">
  <div class="modal-dialog" style="max-width: 72%;">
    <div class="modal-content">
      <form action="" method="POST" id="formView">
      <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Student Details</h4>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>
      <!-- Modal body -->
      <div class="modal-body">
                
                   
                   <div class="row">                                                    
                                                 <div class="col-md-4">                                       
                                                               <div class="card-body">
                                                                   
                                                                    <div class="form-group row">
                                                                        <label for="s_id"
                                                                        class="col-sm-3 text-end  col-form-label">Student ID</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="s_id1" name="s_id1" readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                        S. Name</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="s_name1" name="s_name1" readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                        Batch No</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="text" class="form-control" id="batch_no1" name="batch_no1" readonly/>
                                                                        </div>
                                                                    </div>       
                                                                </div>
                                                            
                                                    </div>
                                                    <div class="col-md-4">
                                                    <div class="card-body">
                                                                   
                                                                   <div class="form-group row">
                                                                       <label for="s_id"
                                                                       class="col-sm-3 text-end control-label col-form-label">C. Name</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="c_name" name="c_name"  readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                       Duration</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="duration1" name="duration1" readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                       Fee</label>
                                                                       <div class="col-sm-9">
                                                                       <input type="text" class="form-control" id="fee1" name="fee1" readonly/>
                                                                       </div>
                                                                   </div>       

                                                               </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                    <div class="card-body">                        
                                                                   <div class="form-group row">
                                                                       <label for="s_id"
                                                                       class="col-sm-3 text-end control-label col-form-label">Shift Time</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="shift_t" name="shift_t" readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                       Start Date</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="s_date1" name="s_date" readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                       End Date</label>
                                                                       <div class="col-sm-9">
                                                                       <input type="text" class="form-control" id="e_date1" name="e_date" readonly/>
                                                                       </div>
                                                                   </div>       
                                                               
                                                               </div>
                                                    </div>  
                                                    <div class="col-md-6">
                                                        <table cellspacing="0" cellpadding="0" border="0" width="100%">
                                                        <tr><td>   
                                                            <div class="card-body">                                                  
                                                              <div class="table-responsive" style="width:100%; height:200px; overflow:auto;">    
                                                                <table id="data-table" class="table">
                                                                  <thead class="table-light">
                                                                    <tr>
                                                                      <th scope="col">Attendence</th>
                                                                      <th scope="col">Attendence (%)</th>                                                           
                                                                    </tr>
                                                                  </thead>
                                                                  <tbody">                       
                                                                        <tr id="tr1"></tr>
                                                                      <thead class="table-light">
                                                                        <tr>
                                                                          <th scope="col">Paid Fee</th>
                                                                          <th scope="col">Paid Fee (%)</th>                                                           
                                                                        </tr>
                                                                      </thead>
                                                                        <tr id="tr2"></tr>
                                                                  </tbody>                  
                                                                </table>  
                                                                </div> 
                                                          </div>
                                                          </td></tr>    
                                                          </table> 
                                                    </div>

                                                    <div class="col-md-6">
                                                      <table cellspacing="0" cellpadding="0" border="0" width="100%">
                                                      <tr><td>   
                                                          <div class="card-body">                                                  
                                                            <div class="table-responsive" style="width:100%; height:200px; overflow:auto;">    
                                                              <table id="data-table" class="table">
                                                                <thead class="table-light">
                                                                  <tr>
                                                                    <th scope="col">S.No</th>
                                                                    <th scope="col">Exam Type</th>                                                           
                                                                    <th scope="col">Exam Date</th>
                                                                    <th scope="col">Status</th>
                                                                  </tr>
                                                                </thead>
                                                                <tbody id="tbody2">                       
                                                                      
                                                                </tbody>                  
                                                              </table>  
                                                              </div> 
                                                        </div>
                                                        </td></tr>    
                                                        </table> 
                                                    </div>
                  
     
                                          </div>
      <!-- Modal footer -->
        <div class="modal-footer">
        
        </div>
        </form>
    </div>
  </div>
</div>
</div>

<!-- The Modal -->
<div class="modal" id="myModal">
  <div class="modal-dialog" style="max-width: 72%;">
    <div class="modal-content">

      <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Assign Course for Student</h4>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>

      <!-- Modal body -->
      <div class="modal-body">
                              <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="card">
                                                            <form class="form-horizontal" id="modelForm1">
                                                                <div class="card-body">
                                                                    <h4 class="card-title">Personal Info</h4>
                                                                    <div class="form-group row">
                                                                        <label for="s_id"
                                                                        class="col-sm-3 text-end control-label col-form-label">Student ID</label>
                                                                        <div class="col-sm-9">
                                                                        <?php
                                                                        if(isset($_POST['s_id']))
                                                                        {
                                                                            echo "<select class='form-control' id='s_id' name='s_id'>";
                                                                            echo "<option></option><option>".$_POST['s_id']."</option></select>";
                                                                           
                                                                        }
                                                                        else
                                                                        {
                                                                          echo  "<input type='text' class='form-control' id='s_id' placeholder='Student ID'/>";

                                                                        }

                                                                        ?>
                                                                          

                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="name" class="col-sm-3 text-end control-label col-form-label">
                                                                        Student Name</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="name"  readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                        Father Name</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="text" class="form-control" id="fname"  readonly/>
                                                                        </div>
                                                                    </div>       
                                                                    <div class="form-group row">
                                                                        <label for="dob" class="col-sm-3 text-end control-label col-form-label">Date of Birth</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control date-inputmask" id="dob" readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="batch_no" class="col-sm-3 text-end control-label col-form-label">Batch No</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="batch_no"  readonly/>
                                                                        </div>
                                                                    </div>  

                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <div class="card">
                                                            <form class="form-horizontal" id="modelForm2">
                                                                <div class="card-body">
                                                                    <h4 class="card-title">Course Info</h4>
                                                                    <div class="form-group row">
                                                                        <label for="s_id" class="col-sm-3 text-end control-label col-form-label">Course Name</label>
                                                                        <div class="col-sm-9">
                                                                            <select class="form-control" id="course">
                                                                            <option></option>
                                                                            <?php                                                                        
                                                                                        $obj->select('course','*',null,null,null,null);
                                                                                        $result=$obj->getResult(); 
                                                                                                                
                                                                                        foreach($result as list("name"=>$name))
                                                                                        {
                                                                                        echo "<option value='{$name}'>$name</option>";                                    
                                                                                        }
                                                                                        ?>
                                                                            </select>
                                                                        </div>
                                                                    </div>  
                                                                    
                                                                    <div class="form-group row">
                                                                        <label for="duration" class="col-sm-3 text-end control-label col-form-label">Duration</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="duration"  readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="desc" class="col-sm-3 text-end control-label col-form-label"> Description</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="desc"  readonly/>
                                                                        </div>
                                                                    </div> 
                                                                    <div class="form-group row">
                                                                        <label for="fee" class="col-sm-3 text-end control-label col-form-label"> Course Fee</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="fee"  readonly/>
                                                                        </div>
                                                                    </div> 
                                                                      <div class="form-group row">
                                                                          <label for="shift_time" class="col-sm-3 text-end control-label col-form-label">Shift Time</label>
                                                                          <div class="col-sm-9">
                                                                              <select class="form-control" id="shift_time">
                                                                                  <option></option>
                                                                                  <?php
                                                                                          
                                                                                          $obj->select('shift','*',null,null,null,null);
                                                                                          $result=$obj->getResult(); 
                                                                                                                  
                                                                                          foreach($result as list("shift_time"=>$shift_time))
                                                                                          {
                                                                                              echo "<option value='{$shift_time}'>$shift_time</option>";                                    
                                                                                          }
                                                                                          ?>
                                                                              </select>
                                                                          </div>
                                                                        </div>  
                                                                        <div class="form-group row">
                                                                            <label for="s_date" class="col-sm-3 text-end control-label col-form-label">Start Date</label>
                                                                            <div class="col-sm-9">
                                                                                <input type="date" class="form-control date-inputmask" id="s_date" value="<?php echo date('Y-m-d');?>"/>
                                                                            </div>
                                                                        </div>
                                                                        <div class="form-group row">
                                                                            <label for="e_date" class="col-sm-3 text-end control-label col-form-label">End Date</label>
                                                                            <div class="col-sm-9">
                                                                                <input type="date" class="form-control date-inputmask" id="e_date" value="<?php echo date('Y-m-d');?>"/>
                                                                            </div>
                                                                        </div> 
                                                                
                                                                </div>
                                                            </form>                                                                                  
                                                      </div>          
                                                    </div>
                              </div>                
      </div>
      <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" id="save_record">Save Record</button>
        </div>

    </div>
  </div>
</div>


<!-- The Modal -->
<div class="modal" id="myModal2">
  <div class="modal-dialog" style="max-width: 52%;">
    <div class="modal-content">

      <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Update Course Record for Student</h4>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>

      <!-- Modal body -->
      <div class="modal-body">
                              <div class="row">
                     
                                                    <div class="col-md-11">
                                                        <div class="card">
                                                            <form class="form-horizontal" id="modelForm">
                                                                <div class="card-body">
                                                                    <h4 class="card-title"></h4>
                                                                    <div class="form-group row">
                                                                        <input type="hidden" class="form-control" id="id2"  readonly/>
                                                                        <label for="s_id" class="col-sm-3 text-end control-label col-form-label">Course Name</label>
                                                                        <div class="col-sm-9">
                                                                            <select class="form-control" id="course2" readonly>
                                                                            <option></option>
                                                                            <?php                                                                        
                                                                                        $obj->select('course','*',null,null,null,null);
                                                                                        $result=$obj->getResult(); 
                                                                                                                
                                                                                        foreach($result as list("name"=>$name))
                                                                                        {
                                                                                        echo "<option value='{$name}'>$name</option>";                                    
                                                                                        }
                                                                                        ?>
                                                                            </select>
                                                                        </div>
                                                                    </div>  
                                                                    
                                                                    <div class="form-group row">
                                                                        <label for="duration" class="col-sm-3 text-end control-label col-form-label">Duration</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="duration2"  readonly/>
                                                                        </div>
                                                                    </div>

                                                                    <div class="form-group row">
                                                                        <label for="fee" class="col-sm-3 text-end control-label col-form-label"> Course Fee</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="fee2"  readonly/>
                                                                        </div>
                                                                    </div> 
                                                                      <div class="form-group row">
                                                                          <label for="shift_time" class="col-sm-3 text-end control-label col-form-label">Shift Time</label>
                                                                          <div class="col-sm-9">
                                                                              <select class="form-control" id="shift_time2">
                                                                                  <option></option>
                                                                                  <?php
                                                                                          
                                                                                          $obj->select('shift','*',null,null,null,null);
                                                                                          $result=$obj->getResult(); 
                                                                                                                  
                                                                                          foreach($result as list("shift_time"=>$shift_time))
                                                                                          {
                                                                                              echo "<option value='{$shift_time}'>$shift_time</option>";                                    
                                                                                          }
                                                                                          ?>
                                                                              </select>
                                                                          </div>
                                                                        </div>  
                                                                        <div class="form-group row">
                                                                            <label for="s_date" class="col-sm-3 text-end control-label col-form-label">Start Date</label>
                                                                            <div class="col-sm-9">
                                                                                <input type="text" class="form-control date-inputmask" id="s_date2" readonly/>
                                                                            </div>
                                                                        </div>
                                                                        <div class="form-group row">
                                                                            <label for="e_date" class="col-sm-3 text-end control-label col-form-label">End Date</label>
                                                                            <div class="col-sm-9">
                                                                                <input type="text"  class="form-control date-inputmask" id="e_date2" readonly/>
                                                                            </div>
                                                                        </div> 
                                                                        <div class="form-group row">
                                                                          <label for="shift_time" class="col-sm-3 text-end control-label col-form-label">Status</label>
                                                                          <div class="col-sm-9">
                                                                              <select class="form-control" id="status2">
                                                                                  <option></option>
                                                                                  <option>Active</option>
                                                                                  <option>Closed</option>
                                                                              </select>
                                                                          </div>
                                                                        </div>  
                                                                </div>
                                                            </form>                                                                                  
                                                      </div>          
                                                    </div>
                              </div>                
      </div>
      <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" id="edit_record">Update Record</button>
        </div>

    </div>
  </div>
</div>

          <footer class="footer text-center">
          All Rights Reserved by ECI. Designed and Developed by
          <a href="https://www.ntlogix.in">NTLogix</a>.
        </footer>
       
   <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="../assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="../assets/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="../assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="../assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="../dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="../dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="../dist/js/custom.min.js"></script>
    <!-- this page js -->
    <script src="../assets/extra-libs/multicheck/datatable-checkbox-init.js"></script>
    <script src="../assets/extra-libs/multicheck/jquery.multicheck.js"></script>
    <script src="../assets/extra-libs/DataTables/datatables.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script>
        
      var msg;
      var icon;
      function showAlert(msg,icon) {
          Swal.fire({
              title: msg,
              icon: icon,
              confirmButtonText: 'Close'
          });
      }
      $(document).ready(function(){
        
                  $("#zero_config").DataTable();  
                  $('#add').click(function(e){
                            e.preventDefault();
                            $("#modelForm1").get(0).reset();
                            $("#modelForm2").get(0).reset();
                            $("#course").prop("disabled",true);  
                            $("#shift_time").prop("disabled",true);  
                            $("#myModal").modal('show');
                    });
                    $(".id").click(function() {
                      var id = $(this).closest('tr').find('td.id').text(); 
                                        $.ajax({
                                              url:"core/fetch-student.php",
                                              method:"post",
                                              data: {
                                                  id:id,
                                                  state:'c_info',                                
                                              },
                                              success: function(data){ 
                                                  $.each(data,function(key,value){  
                                                        $('#batch_no1').val(id);                           
                                                        $('#s_id1').val(value['student_id']);
                                                        $('#s_name1').val(value['student_name']);
                                                        $('#c_name').val(value['course_name']);
                                                        $('#shift_t').val(value['shift_time']);
                                                        $('#fee1').val(value['course_fee']);
                                                        $('#duration1').val(value['course_duration']);
                                                        $('#s_date1').val(value['start_date']);
                                                        $('#e_date1').val(value['end_date']);
                                                         
                                                      })
                                              }
                                          });
                                          $.ajax({
                                              url:"core/fetch-student.php",
                                              method:"post",
                                              data: {
                                                  id:id,
                                                  state:'c_exam',                                
                                              },
                                              success: function(data){ 
                                                var c=0;
                                                  $('#tbody2').empty();
                                                  $.each(data,function(key,value){  
                                                        c=c+1;                                  
                                                        $('#tbody2').append('<tr><td>'+c+'</td><td><a href="#">'+value['exam_type']+'</a></td><td>'+value['exam_date']+'</td><td>'+value['result_status']+'</td></tr>');                                                         
                                                      })
                                              }
                                          });
                                          $.ajax({
                                              url:"core/fetch-student.php",
                                              method:"post",
                                              data: {
                                                  id:id,
                                                  state:'c_att',                                
                                              },
                                              success: function(data){ 
                                                var c=0,d=0;
                                                  $('#tr1').empty();
                                                  $.each(data,function(key,value){  
                                                        c=c+1;                                  
                                                      })
                                                      d=parseInt($('#duration1').val()[0]);
                                                      d=(c*100)/(d*30);
                                                      $('#tr1').append('<td><a href="#">'+c+'</a></td><td>'+d.toFixed(2)+'%</td>');                                                         
                                                     
                                              }
                                          });
                                          $.ajax({
                                              url:"core/fetch-student.php",
                                              method:"post",
                                              data: {
                                                  id:id,
                                                  state:'c_fee',                                
                                              },
                                              success: function(data){ 
                                                var c=0,d=0;
                                                  $('#tr2').empty();
                                                  $.each(data,function(key,value){  
                                                        c=c+parseInt(value['amount']);                                  
                                                      })
                                                      
                                                      d=parseInt($('#fee1').val());
                                                      d=(c*100)/(d);
                                                      $('#tr2').append('<td><a href="#">'+c+'</a></td><td>'+d+'%</td>');                                                         
                                                     
                                              }
                                          });

                      $("#myModal1").modal('show');
                  });

                  $('#course').change(function(){
                      var id = $("#course").val();
                      $.ajax({
                          url:"core/fetch_course.php",
                          method:"post",
                          data: {
                              id:id,                          
                          },
                          success: function(data){                          
                              $('#duration').val(data[0].duration);
                              $('#desc').val(data[0].description);
                              $('#fee').val(data[0].total_fee);
                              if($('#duration').val()==''){
                              $("#shift_time").prop("disabled",true); 
                            }else{
                              $("#shift_time").prop("disabled",false); 
                            }
                          }
                      });
                  });
                  $('#s_id').keypress(function (e) {    
    
                      var charCode = (e.which) ? e.which : event.keyCode    

                      if (String.fromCharCode(charCode).match(/[^0-9]/g))    

                          return false;                        

                  });    
                  $('#s_id').change(function(){
                    var name = $("#s_id").val();
                    
                            $.ajax({
                                url:"core/fetch_student.php",
                                method:"post",
                                data: {
                                    name:name,                          
                                },
                                success: function(data){                                
                                    $('#name').val(data[0].name);
                                    $('#fname').val(data[0].father_name);
                                    $('#dob').val(data[0].dob);
                                    $('#batch_no').val(data[0].batch);
                                    $("#course").prop("disabled",false);                                                           
                                    if(data===0)
                                    {
                                     $('#name').val('');
                                    $('#fname').val('');
                                    $('#dob').val('');
                                    $('#batch_no').val('');                                  
                                    }
                                }
                            });
                      
                });
                $("#zero_config").on("click", ".btn-edit", function() {              
                  var id = $(this).data("id");             
                  $.ajax({
                                url:"core/fetch-student.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'acourse_edit',                                
                                },
                                success: function(data){ 
                                    $.each(data,function(key,value){  
                                          $('#id2').val(id); 
                                          $('#duration2').val(value['course_duration']);
                                          $('#shift_time2').val(value['shift_time']);                          
                                          $('#course2').val(value['course_name']);                                      
                                          $('#fee2').val(value['course_fee']);                                             
                                          $('#s_date2').val(value['start_date']);  
                                          $('#e_date2').val(value['end_date']);  
                                          $('#status2').val(value['status']);                                       
                                        })
                                }
                            });
                  $("#myModal2").modal('show');

                });
                $("#zero_config").on("click", "#id", function() {              
                var id = $(this).data("id");   
                if (confirm('Do you really want to Delete Assign Students!',"")) {                    
                      $.ajax({
                                  url:"core/delete.php",
                                  method:"post",
                                  data: {
                                    id:id,
                                    state:'crs',                          
                                  },
                                  success: function(data){                        
                                    if(data.length===1)
                                    {                                  
                                      showAlert('Assign Course Deleted!','success');
                                      setTimeout(function(){window.location='./assign-Course.php';}, 2000); 
                                      
                                    }
                                  }
                              });
                            }     
              });
              
                $('#save_record').click(function(){
                  
                   var batch_no = $("#batch_no").val();
                   var student_id = $("#s_id").val();
                   var student_name = $("#name").val();
                   var course = $("#course").val();
                   var duration = $("#duration").val();
                   var fee = $("#fee").val();
                   var shift_time = $("#shift_time").val();
                   var start_date = $("#s_date").val();
                   var end_date = $("#e_date").val();  
                    
                   if((batch_no.length===0)||(course.length===0)||(shift_time.length===0)||(fee==='0'))
                    {
                      showAlert('some field is empty!','warning');
                      return 0;
                    } 
                         $.ajax({
                             url:"core/assign-course.php",
                             method:"post",
                             data: {
                                 batch_no:batch_no,
                                 student_id:student_id,
                                 student_name:student_name,
                                 course:course,
                                 duration:duration,
                                 fee:fee,
                                 shift_time:shift_time,
                                 start_date:start_date,
                                 end_date:end_date, 
                                 state:'add',                                                      
                             },
                             success: function(data){                          
                               if(data==1)
                               {
                                 
                                $("#myModal").modal('toggle');
                                showAlert('Course Successfully Assign!','success');
                                setTimeout(function(){window.location='assign-course.php';}, 2000); 
                               }
                             }
                         });
                    
               });
               $('#edit_record').click(function(){
                  var id = $("#id2").val();
                  var shift_time = $("#shift_time2").val();
                  var status = $("#status2").val();
                  if((shift_time.length===0)||(status.length===0))
                   {
                     showAlert('some field is empty!','warning');
                     return 0;
                   } 
                        $.ajax({
                            url:"core/assign-course.php",
                            method:"post",
                            data: {
                                id:id,
                                state:'edit',
                                shift_time:shift_time,  
                                status:status,                                                                          
                            },
                            success: function(data){                          
                              if(data==1)
                              {                               
                               $("#myModal2").modal('toggle');
                               showAlert('Course Successfully Updated!','success');
                               setTimeout(function(){window.location='assign-course.php';}, 2000); 
                              }
                            }
                        });
                   
              });
        });
</script>

  </body>
</html>