<?php
$date=date('Y-m-d',strtotime($this->uri->segment('3')));
$table="school_classes_structure";
$acedemic_session=$this->session->userdata('acedemic_session');
$get_all_courses=$this->AttendenceModel->get_all_classes_structure($acedemic_session);
if($get_all_courses){
    foreach($get_all_courses as $course_data){
        $class=$course_data["class"];
        $section=$course_data["section"];
        $class_teacher=$course_data["class_teacher"];
    }
}

?>

<!DOCTYPE html>
<html>
    <head>
        <title>Attendance</title>
        <style>
            .w-100{width:100%;}
            html{padding:0px;margin:0px;}
            body{padding:15px;margin:0px;font-size:15px;}
            table{border:2px solid;border-collapse:collapse;}
            
            tr td,tr th{border:1px solid;border-collapse:collapse;}
        </style>
        
        
        <style>
            #student {
                font-family: Arial, Helvetica, sans-serif;
                border-collapse: collapse;
                width: 100%;
            }

            #student td, #student th {
                border: 1px solid #ddd;
                padding: 5px;
            }

            #student td{
                font-size:12px;
                text-align:center;
            }

            #student tr:nth-child(even){background-color: #f2f2f2;}

            #student tr:hover {background-color: #ddd;}

            #student th {
                padding-top: 8px;
                padding-bottom: 8px;
                text-align: center;
                background-color: #EAEDED;
                /*color: white;*/
                font-size:13px;
                
            }
        </style>
    </head>
    <body>
        <?php
        if($get_all_courses){
            foreach($get_all_courses as $course_data){
                $class=$course_data["class"];
                $section=$course_data["section"];
                $class_teacher=$course_data["class_teacher"];
        ?>
        <div class="">
            <table class="table table-bordered table-striped" id="student">
                <thead>
                    <tr>
                        <th colspan="5">
                            <?php echo $class."-".$section.", ".date('d-M-Y',strtotime($date)); ?>
                        </th>
                    </tr>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Father Name</th>
                        <th>Mobile Number</th>
                        <th id="anni">Status</th>
                    </tr>    
                </thead>  
                <tbody>
                <?php
                $table='attendence';
                $attendance_data=$this->AttendenceModel->class_attendance_data($date,$class,$section);
                $count = 0;
                $s_count=0;
                if($attendance_data){
                    foreach($attendance_data as $data){
                        $s_count=$s_count + 1;
                        
                        $sid=$data['sid'];
                        $table1='student';
                        $student_information = $this->AttendenceModel->student_data($sid,$table1);
                        if($student_information){
                            foreach($student_information as $info){
                                if($data['status']=='a'){
                                    $count = $count + 1;

                        ?>
                        <tr>
                        <td><?php echo $count;?></td>
                        <td><?php echo $info['student_name'];?></td>
                        <td><?php echo $info['father_name'];?></td>
                        <td><?php echo $info['contact_no'].",".$info['alternate_no'];?></td>
                        <td><?php if($data['status']=='p'){
                        ?>
                        <span class="btn btn-sm btn-success" style="color:green;">Present</span>
                        <?php
                        }else if($data['status']=='a'){
                        ?>
                        <span class="btn btn-sm btn-danger" style="color:red;">Absent</span>
                        <?php
                        } ?></td>
                        </tr>    
                        <?php
                                }
                        }    
                        }
                        }
                        ?>
                        <tr>
                            <td></td>
                            <td></td>
                            <th style="color:blue;">Strength : <?php echo $s_count; ?></th>
                            <th style="color:green;">P : <?php echo $s_count-$count; ?></th>
                            <th style="color:red;">A : <?php echo $count; ?></th>
                        </tr>
                        <?php
                        }
                        else{
                        ?>    
                        <tr><td colspan="5">No data found !!</td></tr>
                        <?php
    
                        }
                        ?>
                </tbody>
            </table>  
         
        </div>
        <?php
            }
        }
        ?>

  
    </body>
</html>    