<?php //error_reporting(0);?>
<!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">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<style>
*{
    margin: 0;
    padding: 0;
    font-size: 18px;
}
@page {
  size: A4;
  margin: 0;
}
@media print {
  html, body {
    width: 210mm;
    height: auto;
  }
}
body
{
    padding: 0;
    margin:0;
    font-size: ;
}
    </style>
</head>
<body>
    <div id="page1-div">  
                         
    <?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)';
    }
     ?>
     <style type="text/css">
        .de_table tr th
        {
            padding:5px;
        }
        .button {
          background-color: red; /* Green */
          border: none;
          color: white;
          padding: 15px 32px;
          text-align: center;
          text-decoration: none;
          display: inline-block;
          font-size: 16px;
        }
        .button_2
        {
            background-color: green; /* Green */
          border: none;
          color: white;
          padding: 15px 32px;
          text-align: center;
          text-decoration: none;
          display: inline-block;
          font-size: 16px;
        }
        .button_3
        {
            background-color: green; /* Green */
          border: none;
          color: white;
          padding: 15px 32px;
          text-align: center;
          text-decoration: none;
          display: inline-block;
          font-size: 16px;
        }
        .button_2
        {
            display: none;
        }
     </style>
    <div style="position:fixed; text-align:left;bottom: 0px;right:0px;font-size:21px">
        <button class="button_3" onclick="window.print()">Print</button>
    </div>
    <script type="text/javascript">
        function remove_bg()
        {
            $('#image').hide();
            $('.button_2').show();
            $('.button').hide()
        }
        function add_bg() {
            $('#image').show();
            $('.button').show();
            $('.button_2').hide();

        }
    </script>
    <div style="position:absolute; text-align:left;top: 150px;left:70px;font-size:21px">
        <table class="de_table" style="width:510px">
            <tr>
                <th style="width:150px">Candidate Name</th>
                <th style="width:20px">:</th>
                <th class="table_details" ><?=$st_id->user_name;?></th>
            </tr>
            <tr>
                <th>Candidate PRN</th>
                <th>:</th>
                <th class="table_details" style="font-size:18px"><?=$st_id->user_reg_id  ?></th>
            </tr>
            <tr>
                <th>Course Name</th>
                <th>:</th>
                <th class="table_details"><?=$exam_data->title  ?></th>
            </tr>
            <tr>
                <th>Course Duration</th>
                <th>:</th>
                <th class="table_details"><?=$exam_data->course_duration_in_month;?> MONTHS</th>
            </tr>
            <tr>
                <th>Name of ATP</th>
                <th>:</th>
                <th class="table_details"><?=strtoupper($atp->user_business_name)?></th>
            </tr>
            <tr>
                <th>Date of Exam</th>
                <th>:</th>
                <th class="table_details"><?php echo date('d-m-Y', strtotime($exam_data->st_student_exam_date))?> <?php echo date('h:i a', strtotime($exam_data->st_student_exam_time))?></th>
            </tr>
        </table>
    </div>
    <img style="position: absolute;z-index: 999;left:600px;top: 150px;" src="<?=base_url()?><?=$st_id->user_photo;?>"  width="100"> 
    <div style="position:absolute;top: 370px;left:70px;z-index: 9999;width:650px">
        <table style="width: 100%;" class="mark_de">
            <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>
    </div>
</div>
</body>
<script>
// window.print();
</script>
</html>
<style type="text/css">
    .mark_de tr th
    {
        padding:10px;
    }
    .mark_de tr td
    {
        height:80px;
        vertical-align: text-top;
        font-size:18px;
        padding-top: 10px;
    }
    .mark_de td, .mark_de th
    {
        text-align:center;
        border: 2px solid black;
        border-collapse: collapse;
    }
    .mark_de
    {
        border: 3px solid black;
        border-radius: 10px;
        border-collapse: collapse;
        border-radius: 10px;
        border-style: hidden;
        box-shadow: 0 0 0 3px #000;
    }
</style>
<?php 
// $this->db->select('a.*, b.*');
//     $this->db->from('student_exam_answer a');
//     $this->db->join('exam_questions b', 'b.q_id = a.question_id');
//     $this->db->where('a.student_id', $exam_data->user_id);
//     $this->db->where('a.exam_id', $exam_data->st_course_id);
//     $answer_details = $this->db->get()->result();
?>
<!-- <div class="row">
      <?php $b=1; foreach ($answer_details as $an_d): ?>
         <div class="col-md-12 col-sm-12 col-lg-12 mt-3" >
            <b>Q<?php echo $b; ?>. <?php echo $an_d->q_question; ?> <?php echo $an_d->student_exam_answer_id; ?></b>
            <ul style="list-style: none;">
                <li>a. <?php echo $an_d->q_ans_a; ?> </li>
                <li>b. <?php echo $an_d->q_ans_b; ?></li>
                <?php if($an_d->q_ans_c): ?>
                  <li>c. <?php echo $an_d->q_ans_c; ?></li>
                <?php endif;
                if($an_d->q_ans_d): ?>
                   <li>d. <?php echo $an_d->q_ans_d; ?></li>
                <?php endif; ?>
            </ul>
            <b>Right Answer : <?php echo $an_d->q_ans_correct; ?></b>
            <br/>
            <?php if($an_d->q_ans_correct == $an_d->answer): ?>
               <span style="color:#00b300"> #Your Answer &nbsp;: <?php echo $an_d->answer; ?> </span>
            <?php elseif($an_d->answer == 'u'): ?>
               <span style="color:#b800e6">   Not Attempted</span>
            <?php else: ?>
               <span class="text-danger"> @Your Answer &nbsp;:  <?php echo $an_d->answer; ?> </span>
            <?php endif; ?>
         </div>
      <?php $b++; endforeach ?>
     </div> -->