<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"><?php echo $this->session->userdata('ac_year'); ?></li> 
                <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>Status</th>
                                <th>Profile</th>
                                <th>Students</th>
                                <th>PDF</th>
                                <th>Upload Signature</th>
                                <th>View Signature</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){
                                if($teacher['user_status'] == 1){ 
                                    $tid=$teacher['id'];
                                    $teachers_sign=$teacher['signature'];
                                    $get_course_info=$this->SchoolModel->get_teacher_course_profile($tid,$acedemic_session);
                                    if($get_course_info){
                                        foreach($get_course_info as $course_info){
                                            $class=$course_info['class'];
                                            $section=$course_info['section'];
                                            
                                            
                    $all_students=$this->WelcomeModel->get_students_ac_session_by_class($acedemic_session,$class,$section);
                    $scount=0;
                    if($all_students){
                    foreach($all_students as $data){
                        $student_table='student';
                        $get_student_data=$this->WelcomeModel->get_item_data($data['sid'],$student_table);
                        if($get_student_data ){
                            foreach($get_student_data as $students){
                                if($students['status'] ==1){
                                    $scount++;
                                }
                            }
                        }
                    }
                    }
                                            $count++;
                        ?>
                        
                        
                            <tr>
                                <td><?php echo $count; ?></td>
                                <td><?php echo $teacher['name']; ?></td>
                                <td><?php echo $teacher['mobile_number']; ?></td>
                                <td><?php echo $teacher['email']; ?></td>
                                <?php
                                
                                ?>
                                <td class="text-center"><?php echo $course_info['class']; ?>-<?php echo $course_info['section'];?></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-outline-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-outline-primary btn-sm'  target="_blank">Profile</a>

                                    </td>
                                    <td>
                                        <a href="<?php echo base_url(); ?>Management/view_class_students/<?php echo $teacher['id']."/".$course_info['class']."/".$course_info['section']; ?>" class="btn btn-sm btn-outline-info" target="_blank">View(<?php echo $scount; ?>)</a>
                                    </td>
                                    <td>
                                        <a href="<?php echo base_url(); ?>Management/view_class_students_pdf/<?php echo $teacher['id']."/".$course_info['class']."/".$course_info['section']; ?>" class="btn btn-sm btn-outline-danger" target="_blank">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-pdf-fill" viewBox="0 0 16 16"><path d="M5.523 10.424c.14-.082.293-.162.459-.238a7.878 7.878 0 0 1-.45.606c-.28.337-.498.516-.635.572a.266.266 0 0 1-.035.012.282.282 0 0 1-.026-.044c-.056-.11-.054-.216.04-.36.106-.165.319-.354.647-.548zm2.455-1.647c-.119.025-.237.05-.356.078a21.035 21.035 0 0 0 .5-1.05 11.96 11.96 0 0 0 .51.858c-.217.032-.436.07-.654.114zm2.525.939a3.888 3.888 0 0 1-.435-.41c.228.005.434.022.612.054.317.057.466.147.518.209a.095.095 0 0 1 .026.064.436.436 0 0 1-.06.2.307.307 0 0 1-.094.124.107.107 0 0 1-.069.015c-.09-.003-.258-.066-.498-.256zM8.278 4.97c-.04.244-.108.524-.2.829a4.86 4.86 0 0 1-.089-.346c-.076-.353-.087-.63-.046-.822.038-.177.11-.248.196-.283a.517.517 0 0 1 .145-.04c.013.03.028.092.032.198.005.122-.007.277-.038.465z"/><path fill-rule="evenodd" d="M4 0h8a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm.165 11.668c.09.18.23.343.438.419.207.075.412.04.58-.03.318-.13.635-.436.926-.786.333-.401.683-.927 1.021-1.51a11.64 11.64 0 0 1 1.997-.406c.3.383.61.713.91.95.28.22.603.403.934.417a.856.856 0 0 0 .51-.138c.155-.101.27-.247.354-.416.09-.181.145-.37.138-.563a.844.844 0 0 0-.2-.518c-.226-.27-.596-.4-.96-.465a5.76 5.76 0 0 0-1.335-.05 10.954 10.954 0 0 1-.98-1.686c.25-.66.437-1.284.52-1.794.036-.218.055-.426.048-.614a1.238 1.238 0 0 0-.127-.538.7.7 0 0 0-.477-.365c-.202-.043-.41 0-.601.077-.377.15-.576.47-.651.823-.073.34-.04.736.046 1.136.088.406.238.848.43 1.295a19.707 19.707 0 0 1-1.062 2.227 7.662 7.662 0 0 0-1.482.645c-.37.22-.699.48-.897.787-.21.326-.275.714-.08 1.103z"/></svg>
                                        </a>
                                    </td>
                                    <td>
                                        <a href="<?php echo base_url(); ?>Staff/upload_signature/<?php echo $teacher['id']."/".$class."/".$section; ?>" target="_blank">Upload</a>

                                    </td>
                                    <td>
                                        <?php
                                        if($teachers_sign){
                                        ?>
                                        <img src="<?php echo base_url(); ?>assets/signature/<?php echo $teachers_sign; ?>" style="width:100px;height:auto;">
                                        <?php
                                        }
                                        ?>
                                    </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>