<style>
.admin-permissions-container{float:right;width:100%;margin-top:20px;box-shadow:0 0 2px silver;margin-bottom:20px;} 
.list-official-staff{width:100%;float:left;box-shadow:0 0 2px silver;margin-top:20px;margin-bottom:20px;}
.form-group{width:100%;padding:10px;}  

@media only screen and (max-width:767px){
.admin-permissions-container{float:right;width:100%;margin-top:20px;box-shadow:0 0 2px silver;margin-bottom:20px;}     
.list-official-staff{width:100%;margin-right:0%;float:left;box-shadow:0 0 2px silver;margin-top:20px;margin-bottom:20px;}    
}
</style>

<div class="container-fluid mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
    
            <div class="list-official-staff">
                <ul class="breadcrumb">
                    <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li>
                    <li class="breadcrumb-item">Management and official staff allocation</li>
                </ul>
                <div class="table-responsive">
                    <table class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>All Admins </th>
                                <th>#</th>
                            </tr>    
                        </thead>    
                        <tbody>


    
                        <?php 
                        $list_admins=$this->SchoolModel->list_admins();

                        if($list_admins){
                            foreach($list_admins as $list){
                                $id=$list['id']; 
                        ?>
                            <tr>
                                <td><?php echo $list['name'];?></td>
                                <td>
                                <?php 
                                if($this->session->userdata('tid')==$id || $list['all_permission']==1 ){ 
                                    echo  "#";
                                }else{
                                ?>
                                <button type="button" class="btn btn-danger remove-admin btn-sm"  val="<?php echo $id;?>">Remove</button>
                                <?php 
                                }
                                ?>
                                </td>
                            </tr>    
                        <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>    
            </div>

            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th>All Management  </th>
                            <th>#</th>
                        </tr>    
                    </thead>    
                    <tbody>
                    <?php 
                    $list_management=$this->SchoolModel->list_management();
                    if($list_management){
                        foreach($list_management as $list){ $id=$list['id']; ?>
                        <tr>
                            <td><?php echo $list['name'];?></td>
                            <td>
                            <?php 
                            if($this->session->userdata('tid')==$id || $list['all_permission']==1 ){ echo  "#";
                            }else{
                            ?>
                                <button type="button" class="btn btn-danger remove-management"  val="<?php echo $id;?>">Remove</button>
                            <?php 
                            }
                            ?>
                            </td>
                        </tr>    
                    <?php
                        }
                    }
                    ?>
                    </tbody>
                </table>    
            </div>

            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th>All Fee Admins</th>
                            <th>#</th>
                        </tr>    
                    </thead>    
                    <tbody>
                    <?php 
                    $list_fee_admins=$this->SchoolModel->list_fee_admins();
                    if($list_fee_admins){
                        foreach($list_fee_admins as $list){ $id=$list['id']; 
                    ?>
                    <tr>
                        <td><?php echo $list['name'];?></td>
                        <td>
                        <?php 
                        if($this->session->userdata('tid')==$id || $list['all_permission'] ==1 ){
                            echo  "#";
                        }else{
                        ?>
                            <button type="button" class="btn btn-danger remove-fee-admin btn-sm"  val="<?php echo $id;?>">Remove</button>
                        <?php 
                        }
                        ?>
                        </td>
                    </tr>    
                    <?php
                        }
                    }
                    ?>
                    </tbody>
                </table>    
            </div>
            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th>All Document Admins</th>
                            <th>#</th>
                        </tr>    
                    </thead>    
                    <tbody>


    
                    <?php 
                    $list_document_admins=$this->SchoolModel->list_document_admins();

                    if($list_document_admins){
                        foreach($list_document_admins as $list){ 
                            $id=$list['id']; 
                    ?>
                        <tr>
                            <td><?php echo $list['name'];?></td>
                            <td>
                            <?php 
                            if($this->session->userdata('tid')==$id || $list['all_permission']==1 ){ echo  "#";}else{
                            ?>
                                <button type="button" class="btn btn-danger remove-document-admin"  val="<?php echo $id;?>">Remove</button>
                            <?php 
                            }
                            ?>
                            </td>
                        </tr>    
                        <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>    
            </div>
        </div>


    
    
        
        </div>
        <div class="col-sm-12">
            <div class="admin-permissions-container">
            <h1 class="main-heading text-center pt-3">Add New </h1><hr>
                <h4><?php if($success){ ?>
                    <p style='color:green;font-weight:bolder;'> <?php echo $success; ?></p>
                <?php } ?>
                <?php if($error){ ?>
                <p style='color:red;font-weight:bolder;'> <?php echo $error; ?></p>
                <?php } ?></h4>
                <form action="#" method="POST">
                    <div class="form-group">
                        <label>Permission type :</label>   
                        <select class="form-control" name="permission_type" required>
                            <option value="">Select permission type</option>    
                            <option value="fee_permission">Add fee admin</option>    
                            <option value="school_management">Add to management</option>
                            <option value="admin">Add new admin</option>
                            <option value="documents">Documents permission</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label>Select</label>
                        <select name="staff" class="form-control" required>
                            <option value="">Select allocation</option>    
                        <?php 
                        $table='school_staff';
                        $get_all_teachers = $this->SchoolModel->get_non_teaching_staff($table);
                        if($get_all_teachers){
                            foreach($get_all_teachers as $teacher){
                        ?>
                            <option value="<?php echo $teacher['id'];?>"><?php echo $teacher['name'];?></option>  
                        <?php    
                            }    
                        }
                        ?>    
                        </select>
                    </div>

                    <div class="form-group">
                        <input type="submit" name="add_to_official" class="btn btn-success btn-sm" value="Add">     
                    </div>

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


<script>
$(document).ready(function(){
$(document).on("click",".remove-admin",function(){
// var id= $(this).val();
var tid=$(this).attr("val");
// alert(tid);

$.ajax({
url: '<?php echo base_url(); ?>management/remove_admin',
type: 'POST',
data: {tid:tid},
success: function(data){
alert(data);    
location.reload();
}
});

});    

$(document).on("click",".remove-management",function(){
// var id= $(this).val();
var tid=$(this).attr("val");
alert(tid);

$.ajax({
url: '<?php echo base_url(); ?>management/remove_management',
type: 'POST',
data: {tid:tid},
success: function(data){
alert(data);    
location.reload();
}
});

});    

$(document).on("click",".remove-fee-admin",function(){
// var id= $(this).val();
var tid=$(this).attr("val");
alert(tid);

$.ajax({
url: '<?php echo base_url(); ?>management/remove_fee_admin',
type: 'POST',
data: {tid:tid},
success: function(data){
alert(data);    
location.reload();
}
});

});    

$(document).on("click",".remove-document-admin",function(){
// var id= $(this).val();
var tid=$(this).attr("val");
alert(tid);

$.ajax({
url: '<?php echo base_url(); ?>management/remove_document_admin',
type: 'POST',
data: {tid:tid},
success: function(data){
alert(data);    
location.reload();
}
});

}); 

});    
</script>