<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
  <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<style>
body{background: #EAEDED;}
/*.teachers-container{background:#fff;padding:20px;min-height:500px; margin-bottom:20px;}*/
a{color:black;}
a:hover{text-decoration:none;}
</style>

<div class="container-fluid teachers-container mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">

            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li> 
                <li class="breadcrumb-item">Staff</li> 
            </ul>           
    
            <a href="<?php echo base_url();?>Management/add_teacher" class="btn btn-sm btn-info mb-3">Add New</a>   
            <a href="<?php echo base_url();?>Management/add_class_teacher" class="btn btn-sm btn-primary mb-3">Class Teachers</a>
            <a href="<?php echo base_url();?>Management/official_permissions" class="btn btn-sm btn-success mb-3">Officials</a>
            <div class="view-teachers">
                <div class="table-responsive">
                    <table class="table table-striped table-bordered" id="mytable">
                        <thead>
                            <tr>
                                <th>#</th>    
                                <th>Name</th>
                                <th>Mobile</th>
                                <th>Email</th>
                                <th>Class Teacher</th>
                                <th>Login Status</th>
                                <th>#</th>
                                <th>Security</th>
                                <th>Edit</th>
                            </tr>
                        </thead>    
                        <tbody>
                        <?php 
                        $teacher_data = $this->SchoolModel->all_teachers();
                        $acedemic_session=$this->session->userdata('acedemic_session');
                        $count=0;
                        if($teacher_data){
                            foreach($teacher_data as $teacher){
                                $tid=$teacher['id'];
                                $count++;
                        ?>
                        
                        
                            <tr>
                                <td><?php echo $count; ?></td>
                                <td><?php echo $teacher['salutation']." ".$teacher['name']; ?></td>
                                <td><?php echo $teacher['mobile_number']; ?></td>
                                <td><?php echo $teacher['email']; ?></td>
                                <td>
                                <?php
                                $get_course_info=$this->SchoolModel->get_teacher_course_profile($tid,$acedemic_session);
                                if($get_course_info){
                                    foreach($get_course_info as $course_info){
                                ?>
                                <?php echo $course_info['class'];?>-<?php echo $course_info['section'];?>
                                    <?php
                                        }
                                    }else{
                                    ?>
                                    
                                    --
                                    <?php
                                        
                                    }
                                    ?>
                                    </td>
                                    <td>
                                        <?php
                                        if($teacher['user_status']==0){  
                                        ?>    
                                            <button class='btn btn-danger active_button inactive' active_attr='0' db_id='<?php echo $teacher['id']; ?>'>Inactive</button>
                                        <?php
                                            
                                        }else{ 
                                        ?>
                                        <button class='btn btn-success active_button btn-sm' active_attr='1' db_id='<?php echo $teacher['id']; ?>'>Active</button>
                                        <?php
                                        }  
                                        ?>
                                    </td>
                                    



                                    <td><a href='<?php echo base_url(); ?>management/staff/<?php echo $teacher['id']; ?>' class='btn btn-primary btn-sm'>Profile</a>

                                    </td>
                                    <td>
                                        <a href="<?php echo base_url(); ?>Management/update_staff_credentials/<?php echo $teacher['id']; ?>" class="btn btn-sm btn-outline-danger"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-lock-fill" viewBox="0 0 16 16"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2z"/></svg></a>
                                    </td>
                                    <td>
                                        <a class="btn btn-sm btn-warning" href="<?php echo base_url()."Management/edit_staff/".$teacher['id']; ?>" target="_blank">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
                                                <path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
                                                <path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
                                            </svg>
                                        </a>
                                    </td>
                                </tr>
                        <?php
                            }    
                        }
                        ?>
                        </tbody>
                    </table>       
                </div>
 
    
            </div>    
        </div>    
    </div>
</div>


<script>
$(document).ready(function() {
    $(document).on("click",".active_button",function(){
        var val = $(this).attr("active_attr");
        var id = $(this).attr("db_id");
        var table = 'school_staff';   
    
        // alert(val);    
        $.ajax({
            url: '<?php echo base_url(); ?>Management/active_inactive_teacher',
            type: 'POST',
            data: { val:val,id:id, table:table},
            success: function(data){
                location.reload();
            }
        });
    }); 
    // $(document).on("click",".delete",function(){
    // var id = $(this).attr("db_id");
    // var table = 'courses';
    // $.ajax({
    // url: 'index.php/Admins/delete_id',
    // type: 'POST',
    // data: {id:id, table:table},
    // success: function(data){
    // location.reload();
    // }
    // });
    // });
    // $('#table').DataTable();
});
</script>