<style type="text/css">
.pp{
float: left !important;
/*width: 33%;  */
color: red;
}  
#tabledata1 tr td{
    text-align:center !important;
}
#thead tr th{
    text-align:center !important;
}
</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
        $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="table-responsive ">
                <table class="table table-bordered table-striped">
                    <tbody>
                        <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="font-weight-bold">Present:</p><p class="present_students text-success font-weight-bold"></p></td>    
                            <td><p class="font-weight-bold">Absent:</p><p class="absent_students text-danger font-weight-bold"></p></td>
                            <td>
                                <p class="font-weight-bold">Total Student  :</p>
                                <p class="font-weight-bold"><?php if($db_check_student>0){echo $db_check_student; }?></p>
                            </td>
                        </tr> 
                    </tbody>
                </table>    
            </div>    
    





            <div id="result" class="text-center"></div>
  
            <div class="table-responsive mt-3" style="margin:0px;">
                <table class="table table-striped table-bordered" id="" style="width:100%;">
                    <thead  id="thead">
                        <tr>
                            <th class="sl_no">Sl.No.</th>  
                            <th>Sch. No.</th>
                            <th>Name</th>
                            <th>Father Name</th>
                            <!--<th>Class</th>-->
                            <th>Mark Attendance</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody id="tabledata1">                                                     

                   
                    </tbody>
                </table>
            </div>

            <form style="text-align: right;" id="myForm" action="<?php echo base_url()?>teacher/attendence" method="post">
                <?php $class = $this->session->userdata('class_teacher');?>    
                <input type="hidden" value="<?php echo $class = $this->session->userdata('class_teacher');?>" name="class">
                <button class="btn btn-sm btn-primary edit" name="close_attendence" value="<?php echo $class = $this->session->userdata('class_teacher');?>" type="submit">Close Attendence</button>
            </form>


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

<script>
$(document).ready(function(){
loadclassstudentdata();
function loadclassstudentdata(){ 
$.ajax({
url: '<?php echo base_url(); ?>teacher/getallstudents',
  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';

// var classs = $(this).attr("classs");
$.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>   
