<style type="text/css">
.pp{
float: left !important;
/*width: 33%;  */
color: red;
}  
</style>
<?php
$class = $this->session->userdata('class_teacher');
$section =$this->session->userdata('class_teacher_section');
$date = date('Y-m-d');
$table='attendence';
$db_check_student=$this->AttendenceModel->class_attendence($class,$section,$date,$table);
?> 
<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();?>Teacher/daily_attendence">Daily Attendance</a></li>
                
            </ul>
               
            <div class="table-responsive" style="margin-top:30px;">
                <table class="table table-bordered table-striped">
                    <tr>
                        <td>Class : <?php echo $class; ?></td>
                        <td>Section : <?php echo $section;?></td>
                        <td>Date : <?php $date = date('d-M-Y'); echo $date;?></td>
                    </tr>    
                    <tr>
                        <td><p class="pp">Present : </p><p class="present_students  text-success"></p></td>    
                        <td><p class="pp">Absent : </p><p class="absent_students  text-danger"></p></td>
                        <td>
                            <p class="pp">Total Student  :
                                <?php if($db_check_student>0){echo $db_check_student; }?>
                            </p>
                        </td>
                   </tr>    
                </table>    
            </div>    

                <div class="table-responsive">
                    <center><div id="result"></div></center>  
                    <table class="table table-striped table-bordered" id="table">
                        <thead>
                            <tr>
                                <th style="width:30px;">#</th>  
                                <th style="width:30px;">Sch. No.</th>
                                <th>Name</th>
                                <th>Father Name</th>
                                <!--<th>Class</th>-->
                                <th>Status</th>
                            </tr>
                        </thead>
                        <tbody id="tabledata1">                                                     
                        </tbody>
                    </table>
                </div>
        </div>
    </div>
</div>

<script>
$(document).ready(function(){
    // $('#table1').DataTable();
    loadclassstudentdata();
    function loadclassstudentdata(){ 
        $.ajax({
            url: '<?php echo base_url() ?>teacher/getattendence',
            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';
        var classs = $(this).attr("classs");
        $.ajax({
            url: '<?php echo base_url() ?>teacher/markin',
            type: 'POST',
            data: { val:val,id:id, table:table,classs:classs},
            success: function(data){
                loadclassstudentdata();
                getPresentStudentsClass();
                getAbsentStudentsClass();
            }   
        });
    });
    $(document).on("click",".present_button",function(){
        var val ='p';
        var id = $(this).attr("db_id");
        var table = 'attendence';
        var classs = $(this).attr("classs");
        $.ajax({
            url: '<?php echo base_url() ?>teacher/markin',
            type: 'POST',
            data: {val:val,id:id,table:table,classs:classs},
            success: function(data){
                loadclassstudentdata();
                getPresentStudentsClass();
                getAbsentStudentsClass();
            }
        });
    }); 

    $("#myForm").submit(function(){
        dataString = $("#myForm").serialize();
        $.ajax({
            type:"POST",
            url:'<?php echo base_url()?>attendence/attendence_note',
            data : dataString,
            success: function(data){
                $("#result").html('Successfully updated record!'); 
                $("#result").addClass("alert alert-success");    
            }
        });  
    });       
});           
</script>   