<?php
$day=$this->uri->segment('3');
$month=$this->uri->segment('4');
$year=$this->uri->segment('5');


$section = $this->session->userdata('class_teacher_section');
$eclass = $this->session->userdata('class_teacher');
// echo date('Y-m-d', mktime( 0, 0, 0, 1, $days, $year));
$day=$this->uri->segment('3');
$month=$this->uri->segment('4');
$year=$this->uri->segment('5');
$d=unixtojd(mktime(0,1,0,$month,$day,$year));
// print_r(cal_from_jd($d,CAL_GREGORIAN));
$ddd=array(cal_from_jd($d,CAL_GREGORIAN));
foreach($ddd as $dd){
    $log_date=date('Y-m-d',strtotime($dd['date']));

?>
<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/attendance_history">Attendance</a></li>
                <li class="breadcrumb-item">Log</li>
                <li class="breadcrumb-item"><?php echo date('d-M-Y',strtotime($log_date)); echo "<span style='color:red;font-weight:600;'> ( ";  echo date('D',strtotime($log_date)); echo " ) </span>";?></li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Date</th>    
                            <th>Strength</th>
                            <th>View</th>
                            <th>Update</th>
                            <th>Action</th>
                        </tr>    
                    </thead>    
                    <tbody>
                        <tr>
                            <td><?php echo date('d-M-Y',strtotime($log_date)); echo "<span style='color:red;font-weight:600;'> ( ";  echo date('D',strtotime($log_date)); echo " ) </span>";?></td>
                            <?php
                            $get_strength=$this->AttendenceModel->attendance_history_by_class($log_date,$eclass,$section);
                            $count=0;
                            $count_present=0;
                            $closed='';
                            if($get_strength){
                                foreach($get_strength as $strength){
                                    $closed=$strength['closed'];
                                    $count ++;    
                                    if($strength['status']=='p'){
                                        $count_present ++;    
                                    }
                            
                                }    
                            }else{
                                $closed=2;    
                            }
                            ?>
                            <td>
                                <?php echo $count;  echo " / "; echo "<span class='text-success font-weight-bolder'>".$count_present."</span>";?></td>
                            <td><a href="<?php echo base_url();?>Teacher/attendance_detail/<?php echo $log_date; ?>" class="btn btn-sm btn-success">View</a></td>
                            <td>
                            <?php
                            $day=$this->uri->segment('3');
                            $month=$this->uri->segment('4');
                            $year=$this->uri->segment('5');
                            $d=unixtojd(mktime(0,1,0,$month,$day,$year));
                            // print_r(cal_from_jd($d,CAL_GREGORIAN));
                            $ddd=array(cal_from_jd($d,CAL_GREGORIAN));
                            foreach($ddd as $dd){
                                // echo $dd['date'];
                                $log_date=date('d-M-Y',strtotime($dd['date']));
                                echo $log_date;
                            }
                            ?>
                            </td>
                            <td>
                            <?php 
                            if($closed ==1){
                            ?>
                                <button class="btn btn-sm btn-success open_attendance text-white">Open Attendance</button>
                            <?php
                            }else if($closed==0){
                            ?>    
                                <a href="<?php echo base_url();?>Teacher/mark_old_attendance/<?php echo date('Y-m-d',strtotime($log_date));?>" class="btn btn-sm btn-warning update_attendance text-white">Update Attendance</a>
                            <?php
                            }else if($closed==2){
                            ?>
                                <a href="<?php echo base_url();?>Teacher/mark_old_attendance/<?php echo date('Y-m-d',strtotime($log_date));?>" class="btn btn-sm btn-info text-white">Mark Attendance</a>
                            <?php
                            }
                            ?>
                            </td>
                        </tr>    
                    </tbody>
                </table>    
            </div>    
        </div>    
    </div>
</div>


<script>
$(document).ready(function(){
    $(".open_attendance").click(function(){
        // alert(note);
        var table = 'attendence';
        var section="<?php echo $section;?>";
        var eclass="<?php echo $eclass;?>";
        var edate="<?php echo date('Y-m-d',strtotime($log_date)); ?>";
        // alert(edate);
        $.ajax({
            type:"POST",
            url:'<?php echo base_url();?>Management/mark_open',
            type: 'POST',
            data:{edate:edate,eclass:eclass,section:section},
            success: function(data){
                alert(data);    
                location.reload();
            }
        });  

    }); 
});
</script>
<?php
}
?>