<?php

    session_start();

    include "../db.php";

    date_default_timezone_set('Asia/Kolkata');

    $currentTime = date('M j, Y g:i a');

    $Sudent = "SELECT * FROM mocktest_result WHERE exam_ref = '$_GET[exam_id]'";

    $SudentRun = mysqli_query($con, $Sudent);

    $SudentResult = mysqli_fetch_assoc($SudentRun);

    $mocktest = "SELECT * FROM mocktest WHERE id = '$SudentResult[mocktest_id]'";

    $mocktestResult = mysqli_query($con, $mocktest);

    $mockRow = mysqli_fetch_assoc($mocktestResult);

    $mockSubject = "SELECT * FROM subject WHERE sc_id = '$mockRow[subject_id]'";

    $mockSubject = mysqli_query($con, $mockSubject);

    $subjectRow = mysqli_fetch_assoc($mockSubject);

    $answerSheet = "SELECT * FROM question WHERE mocktest_id = '$SudentResult[mocktest_id]'";

    $answerSheetRun = mysqli_query($con, $answerSheet);

    

?>



<!DOCTYPE html>

<html lang="en">



<head>

    <?php include "includes/meta.php"; ?>

    <?php include "includes/css.php"; ?>



    <style>

        .modal.fade .modal-dialog {

            width: 100%;

            margin: 0 auto;

        }



        .mock_container {

            background: #f5f5f5;

            padding-top: 100px;

            padding-left: 100px;

            padding-right: 100px;

            padding-bottom: 150px;

        }

        .answer_table tr th,td{

            text-align:center;

        }

    </style>

</head>



<body id="page-top" class="mt-55">



    <div style="margin-top: 70px;"></div>

<?php

$total=0;

$portion=0;

?>

    <?php include "includes/header2.php"; ?>

    <div class="mock_container" style="background: #f5f5f5;">

        <div class="row">

            <div class="col-md-12 col-12 px-0">

                <div class="card px-4 py-2">

                    <div class="card-header text-center text-primary font-weight-bold">

                        <h3>Test Summary</h3>

                    </div>

                    <div class="card-body table-responsive">

                        <table class="table table-borderless">

                            <thead>

                                <tr>

                                    <th scope="col">Student Name</th>

                                    <th scope="col"><?php echo $_SESSION['uname'];?></th>

                                    <th scope="col">Test</th>

                                    <th scope="col"><?php echo $mockRow['mocktest_name'];?></th>

                                </tr>

                            </thead>

                            <tbody>

                                <tr>

                                    <th scope="row">Subject</th>

                                    <td><?php echo $subjectRow['sc_name'];?></td>

                                    <td>Date & Time</td>

                                    <td><?php echo $SudentResult['created_at'];?></td>

                                </tr>

                                <tr>

                                    <th scope="row">Test Duration</th>

                                    <td><?php echo $mockRow['mock_time'].' Minutes';?></td>

                                    <td>Max. Marks</td>

                                    <td><?php echo $SudentResult['total_marks']? $SudentResult['total_marks']:0;?></td>

                                </tr>

                                <tr>

                                    <th scope="row">Obtained marks</th>

                                    <td><?php echo $SudentResult['obtained_marks']? $SudentResult['obtained_marks']:0;?></td>

                                    <td>Percentage</td>

                                    <td>

                                        <?php 

                                        $total = $SudentResult['total_marks'];

                                        if($total==0){

                                            echo '0%';

                                        }else{

                                            $portion = $SudentResult['obtained_marks'];

                                            $percentage = ($portion / $total) * 100;

                                            echo round($percentage,2).'%';

                                        }

                                        

                                        ?>

                                    </td>

                                </tr>

                            </tbody>

                        </table>

                    </div>

                </div>

            </div>

            <div class="col-md-12 col-12 px-0">

                <div class="card px-4 py-2">

                    <div class="card-header text-center text-primary font-weight-bold">

                        <h3>Answer Sheet</h3>

                    </div>

                    <div class="card-body table-responsive">

                        <table class="table table-borderless answer_table">

                            <thead>

                                <tr>

                                    <th scope="col">Q.No</th>

                                    <th scope="col" width="60%">Questions</th>

                                    <th scope="col">Correct Option</th>

                                    <th scope="col">Your Option</th>

                                    <th scope="col">Marks Obtained</th>

                                </tr>

                            </thead>

                            <tbody>

                                <?php foreach($answerSheetRun as $dataKey => $answerSheetData){

                                    $examQuestion = "SELECT * FROM examination WHERE question_id = '$answerSheetData[id]' AND exam_ref='$_GET[exam_id]'";

                                    $examQuestionRun = mysqli_query($con, $examQuestion);

                                    $examQuestionRow = mysqli_fetch_assoc($examQuestionRun);

                                    ?>

                                <tr>

                                    <th><?php echo $dataKey+1?></th>

                                    <th>

                                    <?php if(!empty($answerSheetData['answer_desc'])){

                                        ?><?php echo $answerSheetData['answer_desc'];

                                        }else{

                                            ?>

                                                <img src="../user3/upload/question/<?php echo $answerSheetData['answer_desc_image'];?>" alt="" width="100%">

                                                <?php

                                        }?>

                                    </th>

                                    <td><?php echo $answerSheetData['correct_option'];?></td>

                                    <td><?php echo $examQuestionRow['chosen_option'];?></td>

                                    <td>

                                        <?php if($answerSheetData['correct_option']==$examQuestionRow['chosen_option']){

                                            echo $answerSheetData['marks'];?>

                                            <img src="./img/check.png" alt="">

                                        <?php }else{

                                            echo "0";?>

                                            <img src="./img/cancel.png" alt="">

                                        <?php }?>

                                    </td>

                                </tr>

                                <?php }?>

                            </tbody>

                        </table>

                    </div>

                </div>

            </div>

            <?php include "includes/ft.php"; ?>

            <?php include "includes/js.php"; ?>

        </div>

        <div class="text-center p-4">

            <a href="index.php" class="btn btn-primary">Go to Home Page</a>

        </div>

    </div>

    </div>

</body>

<script>

</script>



</html>