<?php 
$academic_session=$this->session->userdata("acedemic_session");
$ehid=$this->uri->segment("3");
$class=$this->uri->segment("4");
$section=$this->uri->segment("5");
$table="exam_head_master_".$academic_session;
$get_exam_head_information=$this->ExamManagementModel->get_item_data($ehid,$table);
if($get_exam_head_information){
    foreach($get_exam_head_information as $eh_data){
        $class=$eh_data["class"];
        $sch_table="exam_schedule";
        $get_class_exam_schedule=$this->ExamManagementModel->get_class_exam_schedule($class,$ehid,$sch_table);
        $exam_id=$eh_data['exam_id'];
        
        $exam_title=$eh_data['exam_head'];
        $y1=$this->session->userdata("y1");
        $y2=$this->session->userdata("y2");
        
        // LEFT JOIN  exam_schedule ON  exam_schedule.subject_id
?>

<!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>Admit Card</title>
        <style>
            html{padding:0px;margin:0px;}
            body{
                padding:25px;margin:0px;vertical-align:middle;
                font-family: 'Inconsolata', monospace;
            }
            .w-50{
                width:100%;
                height:48%;
                /*float:left;*/
                border:1px solid red;
                /*margin-bottom:10px;*/
            }
            .students-data{
                width:100%;
                /*height:250px;*/
                /*border:1px solid red;*/
            }
            tr th{
                text-align:left;
                padding:0px;
            }
            
            tr td{
                font-size:12px;
                margin-top:0px;
                margin-bottom:0px;
                padding:0px;
            }
        </style>
    </head>
    <body>
    
        <?php
        $acedemic_session=$this->session->userdata('acedemic_session');
        $all_students=$this->ExamManagementModel->get_students_ac_session_by_course_and_class($acedemic_session,$class,$section);

        $scount=0;

        if($all_students){
            foreach($all_students as $students){
                if($students['status'] ==1){
                    $sid=$students['id'];
                       
                    $tid="";
                    $get_class_teacher_data=$this->WelcomeModel->get_class_teacher_for_class_section($class,$section,$acedemic_session);
                    if($get_class_teacher_data){
                        foreach($get_class_teacher_data as $teacher_info){
                            $tid=$teacher_info['class_teacher'];
                        }
                    }
                    $teachers_sign="";
                    $teacher_table="school_staff";
                    $get_teacher_data=$this->WelcomeModel->get_item_data($tid,$teacher_table);
                    if($get_teacher_data){
                        foreach($get_teacher_data as $teacher_data){
                            $teachers_sign=$teacher_data["signature"];
                        }
                    }
                    
                    
                    $profile_pic="";
                    $docs_table="student_data";
                    $get_student_docs_data=$this->ExamManagementModel->get_student_docs_data($sid,$docs_table);
                    if($get_student_docs_data){
                        foreach($get_student_docs_data as $doc_data){
                            $profile_pic=$doc_data['profile_pic'];
                        }
                    }
        ?>
        <div class="w-50">
            <div class="students-data">
                <div>
                    <table class="table" style="width:100%;border-bottom:2px solid #4F3F83;width:100%;">
                        <tr>
                            <th style="width:20%;border:none !important;text-align:center;">
                                <img src='<?php echo logo_png; ?>' style="width:auto;height:40px;" />
                            </th>
                            <th style="width:60%;border:none !important;">
                                <p style="padding:0px; margin:0px;font-size:26px;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:18px;'><b>Affiliated to ICSE / ISC</b></p>
                                
                                <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:18px;'><b>Admit Card - <?php echo $exam_title; ?> <?php echo $y1; ?>-<?php echo $y2; ?></b></p>
                            </th>
                            <th style="width:20%;">
                                
                            </th>
                        </tr>
                    </table>
                    
                    <table style="width:100%;">
                        <tr style="width:100%;margin:0px;padding:0px;">
                            
                            <td  style="border-bottom:1px dotted red;width:40% !important;">
                                Student's Name : <b><?php echo $students['student_name']; ?></b>
                            </td>
                            <td style="border-bottom:1px dotted red;text-align:left !important; width:40% !important;" colspan="2">Class : <b><?php echo $class."-".$section; ?></b></td>
                            <td rowspan="3" style="width:20% !important;">
                                <div style="width:90px;height:120px;border:1px dotted red;margin:15px;background-image:url('<?php echo base_url(); ?>student-data/profile-img/<?php echo $profile_pic; ?>');background-size:cover;">
                                    <?php 
                                    if($profile_pic !=""){
                                    ?>
                                    <!--<img src="<?php echo base_url(); ?>student-data/profile-img/<?php echo $profile_pic; ?>" style="height:auto;width:100% !important;max-height:100%;">-->
                                    <?php
                                    }
                                    ?>
                                </div>
                            </td>
                        </tr>
                        
                        <tr style="width:100%;margin:0px;padding:0px;">
                            <td colspan="" style="border-bottom:1px dotted red;width:40% !important;">Father's Name : <b><?php echo $students['father_name']; ?></b></td>
                            <td colspan="2" style="border-bottom:1px dotted red;text-align:left;width:40% !important;">Mother's Name : <b><?php echo $students['mother_name']; ?></b></td>
                        </tr>
                        <tr style="width:100%;margin:0px;padding:0px;">
                            <td colspan="3">
                                <?php 
                                $exam_subject_master_table="exam_subject_master_".$academic_session;
                                // $class_subjects=$this->ExamManagementModel->get_class_subjects($class,$academic_session,$exam_subject_master_table);
                                
                                $student_subjects_table="student_subjects_".$academic_session;
                                $get_student_subjects=$this->ExamManagementModel->student_subjects_combined($sid,$class,$academic_session,$student_subjects_table,$exam_subject_master_table);
                                if($get_student_subjects){
                                    foreach($get_student_subjects as $subjects_data){
                                        $schedule_exists=0;
                                        // $exam_date=
                                        if($get_class_exam_schedule){
                                            foreach($get_class_exam_schedule as $schd){
                                                if($schd['subject_id'] == $subjects_data['subject_id']){
                                                    $schedule_exists=$schedule_exists + 1;
                                                    $exam_date=$schd['exam_date'];
                                                    echo $subjects_data['subject']." : <u>".date('d-m-Y',strtotime($exam_date))."</u>,&nbsp;";    
                                                }else{
                                                    // echo $subjects_data['subject']." : ".",&nbsp;";
                                                }
                                                
                                            }
                                        }else{
                                            
                                        }
                                        if($schedule_exists == 0){
                                            echo $subjects_data['subject']." : __ __ ____ ".",&nbsp;";
                                        }
                                        
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <!--<th style="text-align:center;vertical-align:bottom;"><br><br>Clerk's Signature</th>-->
                            <th  style="text-align:center;vertical-align:bottom;" colspan="4">
                                
                                <div style="width:33%;float:left;">
                                    <?php
                                    if($teachers_sign !=""){
                                    ?>
                                    <img src="<?php echo base_url(); ?>assets/signature/<?php echo $teachers_sign; ?>" style="height:40px;width:100px;"><br>
                                    <?php }else{ echo "<br><br>"; } ?>    
                                
                                    Class Teacher's Signature
                                </div>
                            <!--</th>-->
                            
                            <!--<th  style="text-align:center;vertical-align:bottom;padding-top:5px;">-->
                                <div style="width:33%;float:left;">
                                    <br>
                                    <br>
                                    <p style="padding:0px;margin:0px;">Stamp</p>
                                </div>
                                <div style="width:33%;float:left;">
                                    <p style="padding:0px;margin:0px;"><img src="<?php echo base_url().PrincipalSign; ?>" style="height:40px;width:100px;"></p>
                                    <p style="padding:0px;margin:0px;">Principal's Signature</p>
                                </div>    
                            <!--</th>-->
                            <!--<th style="text-align:center;vertical-align:bottom;padding-top:5px;">-->
                                
                            </th>
                        </tr>
                        
                    </table>
                </div>
            </div>
        </div>
        <?php
                }
            }
        }
        ?>

    </body>
</html>

<?php
    }
}
?>