<?php
$acedemic_session=3;
$sid=$this->uri->segment('3');
$table='student';
$student_name='';
$father_name='';
$sch_no='';
$roll_no='';
$course_id='';
$course='';
$section='';
$dob='';

$get_student_detail=$this->ReportCardModel->get_item_data($sid,$table);
if($get_student_detail){
    foreach($get_student_detail as $student_detail){
        $student_name=$student_detail['student_name'];
        $father_name=$student_detail['father_name'];
        $dob=date('d-m-Y',strtotime($student_detail['dob']));
        $sch_no=$student_detail['sch_no'];
        // $course=$student_detail['class'];
        // $section=$student_detail['section'];
    }
}


$get_active_course_info=$this->ReportCardModel->student_course_info($sid,$acedemic_session);

if($get_active_course_info){
    foreach($get_active_course_info as $course_info){
        $course_id=$course_info['course_id'];
        $course=$course_info['class'];
        $section=$course_info['section'];
    }
}
$exam_head_table='exam_heads_3';
$get_course_exam_heads=$this->ReportCardModel->get_course_active_exam_heads($course_id,$exam_head_table);


$exam_head_count=0;
if($get_course_exam_heads){
    foreach($get_course_exam_heads as $heads){
        $exam_head_count=$exam_head_count + 1;        
    }
}


$attendance_days=0;
$attendance=0;
$remark='';
$result_table='exam_result';
$exam_id=3;
$roll_no='';
$rank_in_class="";
$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'];
    }
}


$course_subjects_table='exam_subjects_3';
$get_course_exam_subjects=$this->ReportCardModel->get_course_active_subjects($course_id,$course_subjects_table);




?>
<!DOCTYPE html>
<html>
    <head>
        <!--<title>Transfer Certificate</title>-->
        <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>Mid Term Report Card</title>
        <style>
            html{padding:0px;margin:0px;}
            body{
                padding:25px;margin:0px;vertical-align:middle;
                font-family: 'Inconsolata', monospace;
                /*background-image: url("<?php echo logo_png; ?>");*/
                /*opacity: 0.1;*/
                /*background-repeat: repeat;*/
                /*background-size: 10% auto;*/
                /*background-position: center;*/
            }
            
            .report-card{
                /*border:2px solid #a1def4;*/
                border : 2px solid #4F3F83;
                /*height:94.5%;*/
                height:95%;
                border-radius:5px;
                /*outline-offset: -10px;*/
                margin:0px;
                padding:5px;
            }
            .report-2{
                border:1px solid #4F3F83;
                height:96%;
                /*height:auto;*/
                border-radius:5px;
            }
            table{border-collapse:collapse;width:100%;}
            table tr{
                border :1px solid !important;
                border-collapse:collapse;
            }
            tr th{
                margin:0px;
                padding:3px;
                font-size:14px;
                font-weight:700;
                border :1px solid !important;
                border-collapse:collapse;
            }
            /*.report-card-body{*/
            .report-2{
                background-image: url("<?php echo logo_png; ?>");
                opacity: 0.1;
                background-repeat: no-repeat;
                /*background-size: 40% auto;*/
                background-size:auto 40%;
                background-position: center;
            }
        
        
        </style>
    </head>
    <body>
        <div class="report-card p-1">
            <div class="report-2" >
                <div style="height:76px;">
                    <!--<table class="table" style="width:100%;border:1px solid #4F3F83;width:100%;">-->
                    <!--    <tr>-->
                    <!--        <th style="width:15%;border:none !important;">-->
                    <!--            <img src='<?php echo logo_png; ?>' style="width:auto;height:60px;" />-->
                    <!--        </th>-->
                    <!--        <th style="width:85%;border:none !important;">-->
                    <!--            <p style="padding:0px; margin:0px;font-size:36px;text-align:center;font-weight:900;color:#29166f;"><?php echo school_full_name; ?></p>-->
                    <!--            <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:22px;'><b><?php echo school_address; ?></b></p>-->
                                
                    <!--            <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:22px;'><b>FIRST TERM PROGRESS REPORT - SESSION 2022-2023</b></p>-->
                    <!--        </th>-->
                    <!--    </tr>-->
                    <!--</table>-->
                </div>
                <table style="text-align:left;">
                    <tr>
                        <th>
                                        <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:22px;'><b>FIRST TERM PROGRESS REPORT - SESSION 2022-2023</b></p>
                        </th>
                    </tr>
                    <tr>
                        <th style="text-align:left;">
                            
                <div style="width:100%;height:45px;">
                    <div style='width:40%;float:left;margin:0px;padding:0px;'>
                        <p class='pl-1' style='margin:0px;padding:0px;padding-left:5px;text-transform:uppercase;'><b>NAME: </b><?php echo $student_name;?></p>
                        <p class='pl-1' style='margin:0px;padding:0px;padding-left:5px;text-transform:uppercase;'><b>FATHER'S NAME: </b><?php echo $father_name; ?></p>
                    </div>

                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>SCHOLAR NO: </b><?php echo $sch_no; ?></p>
                        <p style='margin:0px;padding:0px;'><b>CLASS: </b><?php echo $course; echo " "; echo $section; ?></p>

                    </div>

                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>ROLL NO: <?php echo $roll_no; ?></b></p>
                        <p style='margin:0px;padding:0px;'><b>D. O. B.: </b><?php echo date('d-m-Y',strtotime($dob)); ?></p>

                    </div>

                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>ATTENDANCE: </b><?php echo round($attendance,2); ?> %</p>

                    </div>
                </div>

                        </th>
                    </tr>
                </table>

                <div style="padding:0px;" class="report-card-body">
                    <table class="table table-bordered" style="width:100%;">
                        <thead>
                            <tr style="margin:0px;padding:0px;background:#DBF7F3;">
                                <th style="text-align:center;margin:0px;font-size:18px;" colspan="7"><b>ACADEMIC PERFORMANCE</b></th>
                            </tr>
                            <tr>
                                <th rowspan="2" colspan="2" style="width:180px;margin:0px;">&nbsp;SUBJECTS</th>
                                <th rowspan="2" style="text-align:center;margin:0px;">MM</th>
                                <?php 
                                
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                ?>
                                <th style="text-align:center;"><?php echo $exam_heads['exam_head'];?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;">Total</th>
                                <th style="margin:0px;text-align:center;">HIC</th>
                            </tr>
                            
                            <tr>
                                
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                ?>
                                <th style="text-align:center;margin:2px;">
                                    <?php echo $exam_heads['mm']; ?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th style="text-align:center;margin:2px;">100</th>
                                <th style="text-align:center;margin:2px;">100</th>
                                
                            </tr>
                        </thead>
                        <tbody>
                            
                            <?php
                            $mm_total=0;
                            $grand_total=0;
                            $hy_grand_total=0;
                            $annual_grand_total=0;
                            if($get_course_exam_subjects){
                                foreach($get_course_exam_subjects as $exam_subjects){
                                    $exam_type=$exam_subjects['exam_type'];
                                    if($exam_type == "Marks"){
                                        $hy_total=0;
                                    
                                    $mm_total=$mm_total + $exam_subjects['MM'];
                                    $sub_total=0;
                                    $subject_id=$exam_subjects['id'];
                                    $sub_type=$exam_subjects['subject_type'];
                                    
                            ?>
                            <tr style="padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;text-align:left;">&nbsp;<?php echo $exam_subjects['subject']; ?></th>
                                <th style="text-align:center;margin:0px;"><?php if($exam_type == "Marks"){ echo $exam_subjects['MM']; } ?></th>
                                
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    if($exam_type == "Marks"){
                                                        $obtained_marks=$elog['obtained_marks'];
                                                    $sub_total=$sub_total + $obtained_marks;
                                                    $hy_total=$hy_total + $obtained_marks;
                                                    $hy_grand_total=$hy_grand_total + $obtained_marks;
                                                ?>
                                                <th style="text-align:center;margin:0px;"><?php echo $elog['obtained_marks']; ?></th>
                                                <?php
                                                }else if($exam_type == "Grade"){
                                                ?>
                                                <th style="text-align:center;margin:0px;"><?php echo $elog['grade']; ?></th>
                                                <?php
                                                }
                                            }
                                        }else{
                                        ?>
                                        <th style="text-align:center;margin:0px;">--</th>        
                                        <?php
                                        }
                                        
                                        }
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;"><?php echo $hy_total; ?></th>
                                <th>--</th>
                                
                                
                            </tr>
                            
                            <?php
                            if($sub_type == "Main Subject"){
                                $grand_total= $grand_total + $sub_total;    
                            }
                                    }
                            
                                }
                            }
                            ?>

                            <?php
                            
                            if($get_course_exam_subjects){
                                foreach($get_course_exam_subjects as $exam_subjects){
                                    $exam_type=$exam_subjects['exam_type'];
                                    if($exam_type == "Grade"){
                                    
                                    
                                    
                                    $subject_id=$exam_subjects['id'];
                                    $sub_type=$exam_subjects['subject_type'];
                                    
                            ?>
                            <tr style="padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;text-align:left;">&nbsp;<?php echo $exam_subjects['subject']; ?></th>
                                <th style="text-align:center;margin:0px;"></th>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                    echo "<th style='text-align:center;margin:0px;'>";    
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    if($exam_type == "Grade"){
                                                
                                                 echo $elog['grade']; 
                                                
                                                }
                                            }
                                        }else{
                                        
                                        echo '--';
                                        
                                        }
                                        
                                        }
                                        echo '</th>';
                                    }
                                }
                                ?>
                                <th>--</th>
                                <th>--</th>
                            </tr>
                        <?php 
                        
                                }
                            }
                        }
                        ?>   
                            <tr style="background:#DBF7F3;border-top:1px solid #4F3F83 !important;padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;">GRAND TOTAL</th>

                                
                                <th style="text-align:center;margin:0px;"><?php echo $mm_total; ?></th>
                                
                                <th></th>
                                <th></th>
                                
                                <th style="text-align:center;margin:0px;"><?php echo $hy_grand_total; ?></th>
                                <th></th>
                            </tr>
                            
                            <?php 
                            $avg_grand_total=$grand_total/2;
                            $percentage="";
                            if($mm_total != 0){
                                $percentage=($grand_total * 100)/$mm_total;    
                            }else{
                                $percentage=0;
                            }
                            
                            ?>
                            <tr style="background:#DBF7F3;border:1px solid #4F3F83;padding:0px;margin:0px;">
                                
                                <th style="margin:0px;text-align:left;padding-left:5px;" colspan="2"> Rank in class : <?php echo $rank_in_class;?></th>
                                <th style="margin:0px;text-align:left;padding-left:5px;" colspan="5"> PERCENTAGE : <b>&nbsp; <?php echo number_format((float)$percentage, 2, '.', ''); ?> % </b></th>
                            </tr>
                            
                        </tbody>
                    </table>        
                    <table class="table table-bordered">
                        <tbody>
                            
                            <!--<tr>-->
                            <!--    <th colspan="2">PERSONALITY TRAITS/NON - SCHOLASTICS</th>-->
                            <!--</tr>-->
                             
                            
                            <tr>
                                <th colspan="2" style="text-align:left;height:80px;">REMARK : <?php echo $remark; ?></td>
                            </tr>
                            <tr>
                                <th colspan="" rowspan="" class="text-center">
                                    <br>
                                    <br>
                                    <br>
                            CLASS TEACHER
                                </th>
                                <th colspan="" rowspan="" class="text-center"> 
                                    <br>
                                    <br>
                                    <br>
                            PRINCIPAL
                                </th>
                            </tr>
                        </tbody>
                    </table>
                </div>
                </div>
                
            </div>
    </body>
</html>    