<?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">
                     Assign Course List
                    </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>Course Name</th>
                          <th>Description</th>
                          <th>No of Student</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                        
                              <?php
                           
                                $obj=new Database();
                                $obj->select('course','*',null,null,'id DESC',null);
                                $result=$obj->getResult(); 
                                $c=0;
                                                              
                                foreach($result as list("id"=>$id,"name"=>$course_name,"description"=>$shift_time))
                                {                                   
                                     
                                    $id="course_name="."'".$course_name."'";
                                    $c_student=$obj->Duplicate_Count('students_course',$id);
                                    if($c_student>0)
                                    {
                                      $c=$c+1; 
                                        echo "<tr><td>$c</td><td class='id'>$course_name</td><td>$shift_time</td><td><a href='#'>$c_student</a></td><td><button type='button' class='badge btn-info btn-view' data-id=".$course_name.">View</button></td></tr>";     
                                    }                                      
                                }
                              
                                ?>
                      </tbody>
                  
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- ============================================================== -->
          <!-- End PAge Content -->
          <!-- ============================================================== -->
          <!-- ============================================================== -->

            <!-- 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"></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-12">         
                                                        <table cellspacing="0" cellpadding="0" border="0" width="100%">
                                                        <tr><td>
                                                        <div class="table-responsive-sm" style="width:100%; height:500px; overflow:auto;">
                                                            <table id="" class="table">
                                                                <thead class="table-light">
                                                                <tr>
                                                                    <th scope="col">S.No</th>
                                                                    <th scope="col">Batch No</th>
                                                                    <th scope="col">Student ID</th>
                                                                    <th scope="col">Student Name</th>  
                                                                    <th scope="col">Shift Time</th>  
                                                                    <th scope="col">Start date</th>  
                                                                    <th scope="col">End date</th>                                                          
                                                                    
                                                                </tr>
                                                                </thead>
                                                                <tbody id="tbody">                       
                                                                    
                                                                </tbody>                  
                                                            </table>
                                                        </div> 
                                                        </td></tr>    
                                                       </table>   
                                                    </div>
                              </div>                
                </div>            
              
                <!-- Modal footer -->
                  <div class="modal-footer">
                       <!-- Modal footer  <button type="button" class="btn btn-danger" id="print_data">Print Data</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(){
                  $("#myModal").modal('show');
            });
            $("table").on("click",".btn-view",function(){             
                    var id = $(this).closest('tr').find('td.id').text();                                                                                                      
                            $.ajax({
                                url:"../admin/core/fetch_course_list.php",
                                method:"post",
                                data: {
                                   id:id,                              
                                },
                                success: function(data){
                                  var c=0;
                                  $('#tbody').empty();
                                  $.each(data,function(key,value){
                                      c=c+1; 
                                        $('#tbody').append('<tr><td>'+c+'</td><td>'+value['batch_no']+'</td><td>'+value['student_id']+'</td><td>'+value['student_name']+'</td><td>'+value['shift_time']+'</td><td>'+value['start_date']+'</td><td>'+value['end_date']+'</td></tr>');                                                                        
                                  })
                                  var title='All Students List of '+id;
                                  $('.modal-title').text(title);
                                }
                            }); 
                            setTimeout(function(){$("#myModal").modal('show');}, 100); 

             });

    });

</script>

  </body>
</html>