<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <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=Dancing+Script:wght@700&family=Roboto&display=swap" rel="stylesheet">
    <title>Hall Ticket</title>
</head>
<?php 
    $this->db->select('user_id, user_atp, user_name, user_reg_id, user_photo');
    $this->db->where('user_reg_id', $reg_id);
    $st_id = $this->db->get('users')->row();

    $this->db->where('user_id', $st_id->user_atp);
    $atp = $this->db->get('users')->row();
    
     $this->db->select('a.*, b.title, b.exam_time, b.course_duration, b.total_questions, b.exam_time, b.online_exam_marks, b.practical_exam_marks, b.viva_exam_marks, b.course_duration_in_month, c.*');
    $this->db->from('student_course a');
    $this->db->join('course b', 'b.id = a.st_course_course_id', 'left');
    $this->db->join('users c', 'c.user_id = a.st_course_student_id', 'left');
    $this->db->where('a.st_course_course_id', $course_id);
    $this->db->where('a.st_course_student_id', $st_id->user_id);
    $exam_data = $this->db->get()->row();


    $this->db->select('a.*, b.*');
    $this->db->from('student_exam_answer a');
    $this->db->join('exam_questions b', 'b.q_id = a.question_id AND b.q_ans_correct = a.answer');
    $this->db->where('a.student_id', $exam_data->user_id);
    $this->db->where('a.exam_id', $exam_data->st_course_id);
    $obtmarks_details = $this->db->get()->num_rows();



   $exam_mark = $exam_data->online_exam_marks / $exam_data->total_questions;
   if($obtmarks_details)
   {
      $obtmarks = $exam_mark * $obtmarks_details; 
   }
   else
   {
      $obtmarks = 0;
   }

    ?>

    <?php
    $totalmarks = doubleval($exam_data->online_exam_marks) + doubleval($exam_data->practical_exam_marks) + doubleval($exam_data->viva_exam_marks);
    $totalobtainedmarks = doubleval($obtmarks) + doubleval($exam_data->prc_obtained_marks) + 
                 doubleval($exam_data->viva_obtained_marks);
    $grade='';
   
    // $per=round((($marks->obtainedmarks) /($marks->totalmarks))*100);   
    $per=round(($totalobtainedmarks/$totalmarks)*100);
    
    if(($per >= 90) && ($per <= 100)){
        $grade='O';
    }
    else if(($per >= 80) && ($per <= 89)){
        $grade='A+';
    }
    else if(($per >= 60) && ($per <= 79)){
        $grade='A';
    }
    else if(($per >= 55) && ($per <= 59)){
        $grade='B';
    }
    else if(($per >= 50) && ($per <= 54)){
        $grade='C';
    }
    else if(($per >= 45) && ($per <= 49)){
        $grade='D (Fail)';
    }
    else if(($per >= 40) && ($per <= 44)){
        $grade='E (Fail)';
    }
    else {
        $grade='F (Fail)';
    }
     ?>
<?php 


    $imagePath = base_url().$st_id->user_photo;

    // Read the image file
    $imageData = file_get_contents($imagePath);

    // Encode the image data as base64
    $base64Image = base64_encode($imageData);

    // Create a data URI for use in HTML or CSS
    $dataImg = 'data:image/jpeg;base64,' . $base64Image;

    ?>
<style type="text/css">
    body
    {
        font-family: 'arial';
font-family: 'arial', sans-serif;
    }
</style>
    <body>
        <table width="100%" border="2" style="border-collapse: collapse;">
            <tr>
                <td colspan="3">
                    <h1 id="center" class="text-center text-primary"><center><?php echo strtoupper(atp_details()->user_business_name); ?></center></h1>
                    <h3><center><?php echo atp_details()->user_reg_id; ?></center></h3>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <h3><center>Online Copy</center></h3>
                </td>
            </tr>
            <tr>
                <td width="20%">
                    <b>ROLL NUMBER</b>
                </td>
                <td width="60%">
                    <?=$st_id->user_reg_id  ?>
                </td>
                <td rowspan="4" style="text-align: center;"><img src="<?php echo $dataImg; ?>" alt=""style="height: 150px;"></td>
            </tr>
            <tr>
                <td>
                   <b> NAME</b>
                </td>
                <td>
                    <?=$st_id->user_name;?>
                </td>
            </tr>
            <tr>
                <td>
                    <b>EXAM DATE</b>
                </td>
                <td>
                    <?=$exam_data->st_student_exam_date  ?>
                </td>
            </tr>
            <tr>
                <td>
                    <b>CENTER NAME</b>
                </td>
                <td>
                    <?=strtoupper($atp->user_business_name)?>
                </td>
            </tr>
            <tr>
                <td style="padding-top: 12px;padding-bottom: 12px;">
                    <b>CENTER CODE
                </td>
                <td colspan="2">
                    <?=$atp->user_reg_id?>
                </td>
            </tr>
            <tr>
                <td style="padding-top: 12px;padding-bottom: 12px;">
                    <b>COURSE
                </td>
                <td colspan="2">
                    <?=$exam_data->title  ?>
                </td>
            </tr>
        </table>

        <table border="2" width="100%" style="border-collapse: collapse;margin-top: 20px;text-align: center;">
            <tr>
                <th width="20%">Course Code</th>
                <th width="20%">Max. Marks</th>
                <th width="20%">Marks of Obtained</th>
                <th width="20%">Percantage & Grade</th>
            </tr>
            <tr>
                <td><?=$exam_data->title;?></td>
                <td><?=$totalmarks?></td>
                <td>Prc. : <?php echo doubleval($exam_data->prc_obtained_marks); ?>
                    <br/>
                    Viva : <?php echo doubleval($exam_data->viva_obtained_marks); ?>
                    <br/>
                    Exam : <?php echo doubleval($obtmarks); ?>
                </td>
                <td><?=$per?>% (<?=$grade;?>)</td>
            </tr>
            <tr>
                <th>Grand total</th>
                <th><?=$totalmarks?></th>
                <th><?=$totalobtainedmarks?></th>
                <th><?=$per?>% (<?=$grade;?>)</th>
            </tr>
        </table>




    </body>
</html>
<style type="text/css">
h1
{
    margin-bottom: 0;
}
h3
{
    margin-top: 10px;
}
.greade
{
    font-size: 10px;
}
.greade td
{
    padding-top: 10px;
    padding-bottom: 10px;
}
.accuracy th, .accuracy td
{
    padding: 10px;
    text-align: center;
}
.center {
  margin-left: auto;
  margin-right: auto;
}
</style>