<?php
$class=$this->uri->segment('3');
$section=$this->uri->segment('4');
$exam_id=$this->uri->segment('5');
$acedemic_session=$this->session->userdata('acedemic_session');


$class_teacher_name="";
$ge_class_teacher_info=$this->ExamManagementModel->get_class_teacher_info($class,$section,$acedemic_session);
if($ge_class_teacher_info){
    foreach($ge_class_teacher_info as $teacher_info){
        $class_teacher_name=$teacher_info["salutation"].' '.$teacher_info['name'];

    }
}

$all_students=$this->ExamManagementModel->get_students_ac_session_by_course_and_class_new($acedemic_session,$class,$section);
$exam_head_table='exam_head_master_'.$acedemic_session;

$exam_id_term_1=1;

$get_term_1_course_exam_heads=$this->ExamManagementModel->get_course_exam_wise_heads($class,$exam_id_term_1,$exam_head_table);

$get_term_2_course_exam_heads=$this->ExamManagementModel->get_course_exam_wise_heads($class,$exam_id,$exam_head_table);

// $get_course_exam_heads=$this->ExamManagementModel->get_course_exam_wise_heads($class,$exam_id,$exam_head_table);

$ehcount_1=count($get_term_1_course_exam_heads);
$ehcount=count($get_term_2_course_exam_heads);
                            
$subject_table='exam_subject_master_'.$acedemic_session;
$get_course_exam_subjects=$this->ExamManagementModel->get_course_active_subjects($class,$subject_table);

$t1_exam_id=1;

$promoted_class="";

if($class == "NURSERY"){
    $promoted_class="LKG";
}else if($class == "LKG"){
    $promoted_class="UKG";
}else if($class == "UKG"){
    $promoted_class=1;
}else{
    $promoted_class=$class + 1;    
}


if($promoted_class == 1){
    $promoted_class=$promoted_class."<sup>st</sup>";
}else if($promoted_class == 2){
    $promoted_class=$promoted_class."<sup>nd</sup>";
}else if($promoted_class == 3){
    $promoted_class=$promoted_class."<sup>rd</sup>";
}else if($promoted_class == 4 || $promoted_class == 5 || $promoted_class == 6 || $promoted_class == 7 || $promoted_class == 8 || $promoted_class == 9  || $promoted_class == 10 || $promoted_class == 11 || $promoted_class == 12){
    $promoted_class=$promoted_class."<sup>th</sup>";
}
?>
<!DOCTYPE html>
<html>
    <head>
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@200;300;400;500;600;700&display=swap" rel="stylesheet"> 
        <title>Term II Report Card</title>
        <style>
            html{padding:0px;margin:0px;}
            body{
                /*padding:15px;*/
                margin:0px;vertical-align:middle;
                font-family: 'Inconsolata', monospace;
            }
            .report-card{
                border : 2px solid #4F3F83;
                height:95%;
                border-radius:5px;
                margin:0px;
                padding:5px;
            }
            .report-2{
                border:1px solid #4F3F83 !important;
                height:96%;
                border-radius:5px;
                
            }
            
            
            .report-card-body{
                background-image: url("<?php echo logo_png; ?>");
                opacity: 0.1;
                background-repeat: no-repeat;
                background-size:auto 40%;
                background-position: center;
            }
            table{border-collapse:collapse;width:100%;}
            table tr{
                /*border :1px solid !important;*/
                border-collapse:collapse;
            }
            tr th{
                margin:0px;
                padding:2px;
                font-size:16px;
                font-weight:700;
                /*border :1px solid !important;*/
                border-collapse:collapse;
            }
            .report-3{
                height:97%;
                /*background-image: url("<?php echo logo_png; ?>");*/
                /*opacity: 0.1;*/
                /*background-repeat: no-repeat;*/
                /*background-size:auto 40%;*/
                /*background-position: center;*/
            }
            .top-section{
                background-image: url("<?php echo base_url(); ?>assets/report-card-left-bg.png");
                /*opacity: 0.1;*/
                background-repeat: no-repeat;
                background-size:cover;
                background-position: center;
            }
        </style>
        
        
        
    </head>
    <body>
        
    <?php

    // var_dump($get_course_exam_heads);
    $count=0;
    if($all_students){
        foreach($all_students as $students){
     
        $t1_height=0;
        $t1_weight=0;
        $height=0;
        $weight=0;
        
        $sid=$students['sid'];
        $student_table='student';
        $course_id=$students['course_id'];
        $roll_no=$students['roll_no'];
        // $height=$students['height'];
        // $weight=$students['weight'];
        
        
        $working_days=0;
        $exam_course_data_table="exam_course_data";
        $get_exam_course_data=$this->ExamManagementModel->get_session_exam_course_data($exam_id,$course_id,$acedemic_session);
        if($get_exam_course_data){
            foreach($get_exam_course_data as $exam_course_data){
                $working_days=$exam_course_data['working_days'];
            }
        }
        
        $t1_working_days=0;
        $get_t1_exam_course_data=$this->ExamManagementModel->get_session_exam_course_data($t1_exam_id,$course_id,$acedemic_session);
        if($get_t1_exam_course_data){
            foreach($get_t1_exam_course_data as $t1_exam_course_data){
                $t1_working_days=$t1_exam_course_data['working_days'];
            }
        }

        // $get_student_data=$this->NewExamModel->get_item_data($sid,$student_table);
        // if($get_student_data ){
        //     foreach($get_student_data as $students){
                    
                // if($students['status'] == 1){
                    $count=$count + 1;
                    if($count <=100){
                        
                        $remark="";
                        $student_name=$students['student_name'];
                        $father_name=$students['father_name'];
                        $mother_name=$students['mother_name'];
                        $dob=date('d-m-Y',strtotime($students['dob']));
                        $sch_no=$students['sch_no'];
                        $blood_group=$students['blood_group'];
                            
                        $attendance_days=0;
                            
                        $attendance=0;
                        $result_table='exam_result';
                        // $exam_id=3;
                        
                        $rank_in_class="";
                        $result_status="";
                        
                        $t1_attendance_days=0;
                        $get_student_t1_exam_data=$this->NewExamModel->get_student_exam_data($sid,$t1_exam_id,$course_id,$result_table);
                        if($get_student_t1_exam_data){
                            foreach($get_student_t1_exam_data as $t1_exam_data){
                                $t1_attendance_days=$t1_exam_data['attendance_days'];
                                $t1_height=$students['height'];
                                $t1_weight=$students['weight'];
                            }
                            
                        }
                        $check_student_exam_data=$this->NewExamModel->get_student_exam_data($sid,$exam_id,$course_id,$result_table);
                        if($check_student_exam_data){
                            foreach($check_student_exam_data as $exam_data){
                                $attendance_days=$exam_data['attendance_days'];
                                    $remark=$exam_data['remark'];
                                    // $attendance=$exam_data['attendance'];
                                    // $roll_no=$exam_data['roll_no'];
                                    $rank_in_class=$exam_data['rank_in_class'];
                                    $result_status=trim($exam_data["result_status"]);
                                    $height=$students['height'];
                                    $weight=$students['weight'];
                                }
                            }
                            
                            if($working_days > 0){
                                $attendance=$attendance_days * 100/$working_days;
                            }
                            
                            
                            $avg_attendance=0;
                            $avg_working_days=$working_days + $t1_working_days;
                            $avg_attendance_days=$attendance_days + $t1_attendance_days;
                            if($avg_working_days > 0){
                                $avg_attendance=$avg_attendance_days * 100/$avg_working_days;
                            }
                            // $exam_head_table='exam_heads_3';
// $get_course_exam_heads=$this->ReportCardModel->get_course_active_exam_heads($course_id,$exam_head_table);
                            
// $course_subjects_table='exam_subjects_3';
// $get_course_exam_subjects=$this->ReportCardModel->get_course_active_subjects($course_id,$course_subjects_table);



$student_subjects_table="student_subjects_".$acedemic_session;
$get_student_subjects=$this->ExamManagementModel->get_student_subjects($sid,$course_id,$acedemic_session,$student_subjects_table);



$elog_table="exam_log_".$acedemic_session;
$get_exam_log=$this->NewExamModel->students_exam_log($sid,$acedemic_session,$elog_table);
?>
        <div style="width:100%;height:100%;" class="top-section">
            <!--<img src="" style="width:100% !important;height:auto !important;">-->
            
            
                <table style="border:none !important;width:100% !important;">
                    <tr style="border:none !important;width:100% !important;">
                        <th style="width:50% !important; border:none !important;">
                            
                        </th>
                        <th style="width:50% !important;padding:100px 25px; border:none !important;">
                            <div style="border:solid 2px !important;border-radius:15px;padding:5px;">
                            <table style="">
                                <tr style="border:none !important;">
                                    <th colspan="2" style="border:none !important;">
                                        <img src='<?php echo school_logo_full_1; ?>' style="width:auto;height:100px;" /><br><br>
                                        



                                        <p style="padding:0px; margin:0px;font-size:20px;text-align:center;font-weight:900;color:#29166f;letter-spacing:0.3px !important;white-space:nowrap !important;"><?php echo school_full_name_1; ?></p>
                                        <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:18px;'><b><?php echo school_address_1; ?></b></p>
                                
                                        <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:18px;'><b>PROGRESS REPORT 2023-2024</b></p>
                                    </th>
                                </tr>
                                <tr style="border:none !important;">
                                    <th colspan="2" style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;text-transform:uppercase;">
                                        NAME: <?php echo $student_name; ?>
                                    </th>
                                </tr>
                                <tr style="border:none !important;">
                                    <th colspan="2" style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;text-transform:uppercase;">MOTHER'S NAME : <?php echo $mother_name; ?></th>
                                </tr>
                                <tr style="border:none !important;">
                                    <th colspan="2" style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;text-transform:uppercase;">FATHER'S NAME : <?php echo $father_name; ?></th>
                                </tr>
                                <tr style="border:none !important;">
                                    <th style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;">D.O.B. : <?php echo $dob; ?></th>
                                    <th style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;text-transform:uppercase;">BLOOD GROUP : <?php echo $blood_group; ?></th>
                                </tr>
                                <tr style="border:none !important;">
                                    <th style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;">CLASS : <?php echo $class; ?></th>
                                    <th style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;">SECTION : <?php echo $section; ?></th>
                                </tr>
                                <tr style="border:none !important;">
                                    <th style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;">ROLL NO. : <?php echo sprintf("%02d",$roll_no); ?></th>
                                    <th style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;">REG. NO. : <?php echo $sch_no; ?></th>
                                </tr>
                                <tr style="border:none !important;">
                                    <th colspan="2" style="text-align:left;font-size:16px;border-bottom:dotted 1px;padding:5px;text-transform:uppercase;">CLASS TEACHER'S NAME : <?php echo $class_teacher_name; ?></th>
                                </tr>
                            </table>
                            </div>
                        </th>
                    </tr>
                </table>
            
        </div>
        
          
        <?php
                            }
                        // }
                //     }
                // }
            }
        }
        ?>
    </body>
</html>