<?php session_start();
require_once 'config.php';
require_once 'auth.php';
$PageName = "Payment Receipt";
$UserId = $_SESSION['User']['id'];
 ?>
<!doctype html>
<html lang="en" class="h-100">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="generator" content="">
    <title><?php echo $Proj_Title; ?></title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <link rel="apple-touch-icon" href="img/favicon180.png" sizes="180x180">
    <link rel="icon" href="img/favicon32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="img/favicon16.png" sizes="16x16" type="image/png">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&amp;display=swap" rel="stylesheet">
    <link href="vendor/swiper/css/swiper.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" id="style">
</head>

<body class="body-scroll d-flex flex-column h-100 menu-overlay">
    <main class="flex-shrink-0 main">
         <header class="header">
            <div class="row">
                
                <div class="text-left col align-self-center">
                    <a class="navbar-brand" href="#">
                        <h5 class="mb-0">Result Summary</h5>
                    </a>
                      
                </div>
                
            </div>
        </header>
          <?php 
    $UserId = $_GET['userid'];
    $ResultId = $_GET['resultid'];
    $TestId = $_GET['testid'];
    $sql2 = "SELECT * FROM tbl_sch_result_answer WHERE ResultId='$ResultId' AND UserId='$UserId' AND Answer=11";
    $rncnt2 = getRow($sql2);

    $sql5 = "SELECT * FROM tbl_sch_result_answer WHERE ResultId='$ResultId' AND UserId='$UserId' AND Answer!=11";
    $rncnt5 = getRow($sql5);

    $TotCorrAns = 0;
    $sql3 = "SELECT Answer,id FROM tbl_sch_question_answer WHERE TestSeriesId='$TestId'";
    $rncnt3 = getRow($sql3);
    $row3 = getList($sql3);
    foreach($row3 as $result){
      $QuesId = $result['id'];
      $CorrAns = $result['Answer'];
      $sql4 = "SELECT * FROM tbl_sch_result_answer WHERE QuesId='$QuesId' AND ResultId='$ResultId' AND Answer!=11";
      $row4 = getRecord($sql4);
      $GiveAnswer = $row4['Answer'];
       //echo $CorrAns." - ".$GiveAnswer."&nbsp;";
      if($CorrAns == $GiveAnswer){
       
           $TotCorrAns = $TotCorrAns + 1;
      }
    }
     $wrong = $rncnt5 - $TotCorrAns;

     $sql6 = "SELECT * FROM tbl_scholarship WHERE id='$TestId'";
     $row6 = getRecord($sql6);
     $CorrectPts = $row6['CorrectMark'];
     $IncorrectPts = $row6['IncorrectMark'];
     $UnattemptedPts = $row6['UnattemptedMark'];
     $tot_result = ($TotCorrAns* $CorrectPts) + ($wrong*$IncorrectPts) + ($rncnt2*$UnattemptedPts);
     $outofmarks = $rncnt3*$CorrectPts;
     $percentage = ($tot_result/$outofmarks) * 100;

     $sql9 = "SELECT MAX(Marks) As MaxMarks FROM tbl_result WHERE TestId='$TestId'";
     $row9 = getRecord($sql9);

     $sql7 = "SELECT MIN(Marks) As MinMarks FROM tbl_result WHERE TestId='$TestId'";
     $row7 = getRecord($sql7);

     $sql8 = "SELECT SUM(Marks) As SumMarks,Count(id) As Studs FROM tbl_result WHERE TestId='$TestId' AND UserId!=0";
     $row8 = getRecord($sql8);
     $AvgMarks = $row8['SumMarks']/$row8['Studs'];
    ?>
        <div class="main-container">
            <div class="container">
                
                <div class="card-body px-0">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <div class="row align-items-center">
                                   
                                    <div class="col align-self-center pr-0">
                                        <h6 class="font-weight-normal mb-1"><strong style="color: blue;">ATTEMPTED</strong></h6>
                                     
                                    </div>
                                    <div class="col-auto">
                                        <h6 class="text-info"><?php echo $TotCorrAns+$wrong+$rncnt2 - $rncnt2;?></h6>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="list-group-item">
                                <div class="row align-items-center">
                                   
                                    <div class="col align-self-center pr-0">
                                        <h6 class="font-weight-normal mb-1"><strong style="color: red;">UNATTEMPTED</strong></h6>
                                     
                                    </div>
                                    <div class="col-auto">
                                        <h6 class="text-danger"><?php echo $rncnt2;?></h6>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="list-group-item">
                                <div class="row align-items-center">
                                   
                                    <div class="col align-self-center pr-0">
                                        <h6 class="font-weight-normal mb-1"><strong style="color: green;">SCORE</strong></h6>
                                     
                                    </div>
                                    <div class="col-auto">
                                        <h6 class="text-success"><?php echo $tot_result;?></h6>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="list-group-item">
                                <div class="row align-items-center">
                                   
                                    <div class="col align-self-center pr-0">
                                        <h6 class="font-weight-normal mb-1"><strong style="color: orange;">PERCETANGE</strong></h6>
                                     
                                    </div>
                                    <div class="col-auto">
                                        <h6 class="text-warning"><?php echo number_format($percentage,2);?> %</h6>
                                    </div>
                                </div>
                            </li>
                           
                        </ul>
                      
                    </div>
                    <div  align="center">
                 <a href="view-sch-result.php?testid=<?php echo $TestId; ?>" class="btn btn-success btn-finish">View Result</a>
                     
               </div>
            </div>
        </div>
    </main>

<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="vendor/swiper/js/swiper.min.js"></script>
<script src="js/main.js"></script>
<script src="js/color-scheme-demo.js"></script>
<script src="js/app.js"></script>
</body>
</html>
