<style type="text/css">
.pp{
float: left !important;
/*width: 33%;  */
/*color: red;*/
}  
tr td{
    padding:5px !important;
    text-align:center;
}
</style>
<div class="container-fluid 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">
                    <a href="<?php echo base_url(); ?>Welcome">Attendance</a>
                </li>
            </ul>
            <?php 
            $acedemic_session=$this->input->post('acedemic_session');
            $class=$this->session->userdata('class_teacher');
            $section =$this->session->userdata('class_teacher_section');
            $date=date('Y-m-d'); 
            $table='attendence';  
            // $class_strength=0;
            $db_check_student=$this->AttendenceModel->class_attendence($class,$section,$date,$table);
            ?>    
            <div class="table-responsive" style="margin-top:30px;">
                <table class="table table-bordered table-striped">
                    <tr>
                        <td style="width:33%;">Class : <?php echo $class; ?></td>
                        <td style="width:33%;">Section : <?php echo $section;?></td>
                        <td style="width:33%;">Date : <?php $date = date('d-M-Y'); echo $date;?></td>
                    </tr>    
                    <tr>
                        <td style="width:33%;"><p class="text-success font-weight-bold">Present : <span class="present_students"></span></p></td>    
                        <td style="width:33%;"><p class="text-danger font-weight-bold">Absent : <span class="absent_students"></span></p></td>
                        <td style="width:33%;">
                            <p class="text-info font-weight-bold">Total Student  :
                            <?php if($db_check_student>0){echo $db_check_student; }else{echo $db_check_student;}?></p>    
                        </td>
                    </tr>    
                </table>    
            </div>

            <center><div id="result"></div></center>  
            <div class="table-responsive">
                <table class="table table-stretched table-bordered" id="table">
                    <thead>
                        <tr>
                            <th>Sl.No.</th>  
                            <th>Roll No.</th>
                            <th>Sch.No.</th>
                            <th>Name</th>
                            <th>Father Name</th>
                            <th>Action</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody id="tabledata1">
                    </tbody>
                </table>
                <a style="text-align: right;" href="<?php echo base_url()?>teacher/final_attendence/<?php echo $class = $this->session->userdata('class_teacher');?>">
                    <button class="btn btn-primary edit btn-sm mt-3" value="" type="submit">Submit Attendence</button>
                </a>
            </div>
        </div>
    </div>
</div>
<script>
$(document).ready(function(){

    function loadclassstudentdata(){ 
        $.ajax({
            url:'<?php echo base_url() ?>Teacher/getallstudent',
            type: 'POST',
            success: function(data){
                $('#tabledata1').html(data);
            }
        });
    } 
    loadclassstudentdata();
    function getPresentStudentsClass(){
        $.ajax({
            url:'<?php echo base_url();?>Teacher/getPresentStudentsinClass',
            type:'POST',
            success:function(data){
                $('.present_students').html(data);
            }           
        });  
    }
    function getAbsentStudentsClass(){
        $.ajax({
            url:'<?php echo base_url();?>Teacher/getAbsentStudentsinClass',
            type:'POST',
            success:function(data){
                $('.absent_students').html(data);
            }
        });
    }
    getPresentStudentsClass();
    getAbsentStudentsClass();
    $(document).on("click",".absent_button",function(){
        var val = 'a';
        var id = $(this).attr("db_id");
        var table = 'attendence';
        $.ajax({
            url: '<?php echo base_url(); ?>teacher/markin',
            type: 'POST',
            data: { val:val,id:id, table:table},
            success: function(data){
                loadclassstudentdata();
                getPresentStudentsClass();
                getAbsentStudentsClass(); 
            }
        });
    });
    $(document).on("click",".present_button",function(){
    
        var val ='p';
        var id = $(this).attr("db_id");
        var table = 'attendence';
    
        $.ajax({
            url: '<?php echo base_url(); ?>teacher/markin',
            type: 'POST',
            data: { val:val,id:id, table:table},
            success: function(data){
                loadclassstudentdata();
                getPresentStudentsClass();
                getAbsentStudentsClass(); 
            }
        });
    }); 
    $("#myForm").submit(function(){
        dataString = $("#myForm").serialize();
        $.ajax({
            type:"POST",
            url:'<?php echo base_url();?>teacher/attendence_note',
            data : dataString,
            success: function(data){
                $("#result").html('Successfully updated record!'); 
                $("#result").addClass("alert alert-success");    
            }
        });  
    });       
});           
</script>