<style>
.attendance-div{
    
}
</style>
<?php
$day=$this->uri->segment('3');
$month=$this->uri->segment('4');
$year=$this->uri->segment('5');

?>

<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">Management</li>    
                <li class="breadcrumb-item">Attendance</li>
                <li class="breadcrumb-item"><?php echo $day;echo"-";echo $month;echo"-";echo $year;?></li>

            </ul>    
            <a href="<?php echo base_url(); ?>Management/all_courses_attendance_report/<?php echo $year."-",$month."-".$day; ?>" target="_blank" class="btn btn-sm btn-danger mb-3">Export All Class Attendance Report</a>
            <div class="attendance-div">
                <div class="table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>Class</th>
                                <th>Teacher Name</th>

                                <th>Strength</th>
                                <th>P/A</th>
                                <th>Status</th>
                                <th>View</th>
                            </tr>    
                        </thead>    
                        <tbody>
                        <?php 
                        $class_teacher_list=$this->SchoolModel->class_teacher_list();

                        if($class_teacher_list){
                        foreach($class_teacher_list as $list){
                        $class=$list['class'];    
                        $section=$list['section'];
                        ?>
                        <tr>
                            <td><?php echo $class;  echo "-"; echo $section; ?></td>
                            <td>
                            <?php
                            $tid= $list['class_teacher'];
                            $get_teacher_name=$this->SchoolModel->get_teacher_name($tid);
                            if($get_teacher_name){
                                foreach($get_teacher_name as $teacher){
                                    echo $teacher['name'];   echo "<br>";
                                    echo $contact_no=$teacher['mobile_number'];

    
                                }    
                            }
                            ?>    
                            </td>
                            <td>
                            <?php
                            $class_student_data=$this->StudentModel->my_class_students($class,$section);

                            if($class_student_data){
                                $class_student_count=0;    
                                foreach($class_student_data as $class_data){
                                    $class_student_count=$class_student_count + 1;    
                                    // echo $class_data['student_name'];
                                }    
                                echo $class_student_count;

                            }

                            ?>    
                            </td>
                            <?php 
                            $date=date('y-m-d');

                            $class_present_count=0;
                            $class_absent_count=0;   
                            $class_status='';
                            $date1=date_create("$year-$month-$day");
                            $at_date= date_format($date1,"Y-m-d");
                            $class_attendance_data=$this->AttendenceModel->class_attendance_data_history($day,$month,$year,$class,$section);

                            if($class_attendance_data){
 
                            foreach($class_attendance_data as $attendance_data){
                            $at_date=$attendance_data['date'];
                            if($attendance_data['status'] == 'a'){
                            $class_absent_count=$class_absent_count + 1;    
                            }else if($attendance_data['status'] == 'p'){
                            $class_present_count=$class_present_count + 1;    
                            }
                            $class_status=$attendance_data['closed'];

                            }
                            // echo $class_present_count;
                            }
                            else{
                                // echo "wrong something";
                                $class_status=2;
                            }
                            ?>
                            <td><?php echo "<span class='text-success font-weight-bolder'>".$class_present_count." /</span>"; echo "<span class='text-danger font-weight-bolder'>".$class_absent_count."</span>";?></td>
                                    <td><?php if($class_status==2){?>

                                        <!--<span class="badge rounded-pill bg-danger"><i>Not Started</i></span>-->
                                        <svg width="2em" height="2em" viewBox="0 0 16 16" class="bi bi-diamond text-danger" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                        <path fill-rule="evenodd" d="M6.95.435c.58-.58 1.52-.58 2.1 0l6.515 6.516c.58.58.58 1.519 0 2.098L9.05 15.565c-.58.58-1.519.58-2.098 0L.435 9.05a1.482 1.482 0 0 1 0-2.098L6.95.435zm1.4.7a.495.495 0 0 0-.7 0L1.134 7.65a.495.495 0 0 0 0 .7l6.516 6.516a.495.495 0 0 0 .7 0l6.516-6.516a.495.495 0 0 0 0-.7L8.35 1.134z"/>
                                    </svg>
                                    <?php }else if($class_status==0){ ?>
                                    <svg width="2em" height="2em" viewBox="0 0 16 16" class="bi bi-diamond-half text-warning" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                        <path fill-rule="evenodd" d="M9.05.435c-.58-.58-1.52-.58-2.1 0L.436 6.95c-.58.58-.58 1.519 0 2.098l6.516 6.516c.58.58 1.519.58 2.098 0l6.516-6.516c.58-.58.58-1.519 0-2.098L9.05.435zM8 .989c.127 0 .253.049.35.145l6.516 6.516a.495.495 0 0 1 0 .7L8.35 14.866a.493.493 0 0 1-.35.145V.989z"/>
                                    </svg>
                                        <?php }else if($class_status==1){ ?>
                                    <svg width="2em" height="2em" viewBox="0 0 16 16" class="bi bi-diamond-fill text-success" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                        <path fill-rule="evenodd" d="M6.95.435c.58-.58 1.52-.58 2.1 0l6.515 6.516c.58.58.58 1.519 0 2.098L9.05 15.565c-.58.58-1.519.58-2.098 0L.435 9.05a1.482 1.482 0 0 1 0-2.098L6.95.435z"/>
                                    </svg>
                                <?php } ?>


                                </td>
                                <td><a href="<?php echo base_url();?>Management/attendance_detail/<?php echo $at_date; echo "/"; echo $tid."/".$class."/".$section;?>" class="btn btn-sm btn-outline-info">View</a></td>
                                <td>
                                    <a href="<?php echo base_url(); ?>Management/class_date_wise_attendance_pdf/<?php echo $at_date; echo "/"; echo $tid."/".$class."/".$section;?>" target="_blank" class="btn btn-sm btn-outline-danger">PDF</a>
                                </td>
                            </tr>    
                            <?php } } ?>
                        </tbody>
                    </table>
                </div>    
            </div>    
        </div>
    </div>
</div>