<?php

session_start();
if (isset($_SESSION['uid'])) {
    include "../config/database.php";
    include_once "../resources/offering.php";
    include_once '../config/properties.php';

    // initialize objects
    $offering = new Offering();
    $offering_id = $_GET['offer'];
    $user_id = $_GET['user'];
    $score_flag = $_GET['score_flag'];
    $offering->offering_id = $offering_id;
    $offering->user_id = $user_id;
    $overall_score = 0;
    $overall_result = '';
    $user_result = $offering->get_user_result();
    if ($user_result->rowCount() > 0) {
        if ($row8 = $user_result->fetch(PDO::FETCH_ASSOC)) {
            $overall_score = $row8['score'];
            $overall_result = $row8['result'];
        }
    }
    if($overall_result == "awaited"){
        $max = $offering->get_max_attempt();
        $max_1= $max - 1;
        $stmt_ass1=$offering->get_all_without_last($max_1);
        while($row_ass1 = $stmt_ass1->fetch(PDO::FETCH_ASSOC)){
            extract($row_ass1);
        echo "<tr class='bg-white shadow-1 rounded-8 border-light'>";
            echo "<td>".htmlentities($assessment_name)."</td>";
            echo "<td>"
                . "<div class='about-content'>"
                  ."<div class='bg-green-2 about-content-list__icon'>"
                    ."<svg xmlns='http://www.w3.org/2000/svg' width='24'"
                      ." height='24' viewBox='0 0 24 24' fill='none'"
                       ."stroke='#000' stroke-width='2'"
                       ."stroke-linecap='round' stroke-linejoin='round'"
                       ."class='fa fa-check icon'>"
                      ."<polyline points='20 6 9 17 4 12'>"
                     ."</polyline>"
                    ."</svg>"
                 ."</div>"
                ."</div></td>";
            echo "<td><span class='text-11 rounded-16 text-black bg-blue-6 py-5 px-5'>"._("TB103")."</span></td>";
            echo "<td>$passing_score</td>";
            echo "<td>$weightage</td>";
            echo "<td>$attempt_no</td>";
            if ($score_flag == "Yes") {
                echo "<td>";
                echo $score;
                echo "</td>";
            }
            if ($score >= $passing_score) {
                $result = 'complete';
            } else {
                $result = 'incomplete';
            }
            $result_bg = $result == "complete" ? "bg-green-2" : "bg-red-2";
            echo "<td><span class='text-11 rounded-16 text-blue-3 {$result_bg} py-5 px-5'>{$result}</span></td>";
        echo "</tr>";
        }
        $stmt_ass2=$offering->get_all_only_last($max_1);
        $row_ass2 = $stmt_ass2->fetch(PDO::FETCH_ASSOC);
        extract($row_ass2);
        echo "<tr class='bg-white shadow-1 rounded-8 border-light'>";
        echo "<td>".htmlentities($assessment_name)."</td>";
        echo "<td>"
                . "<div class='about-content'>"
                  ."<div class='bg-green-2 about-content-list__icon'>"
                    ."<svg xmlns='http://www.w3.org/2000/svg' width='24'"
                      ." height='24' viewBox='0 0 24 24' fill='none'"
                       ."stroke='#000' stroke-width='2'"
                       ."stroke-linecap='round' stroke-linejoin='round'"
                       ."class='fa fa-check icon'>"
                      ."<polyline points='20 6 9 17 4 12'>"
                     ."</polyline>"
                    ."</svg>"
                 ."</div>"
            ."</div></td>";
        echo "<td><span class='text-11 rounded-16 text-black bg-blue-6 py-5 px-5'>"._("TB103")."</span></td>";
        echo "<td>$passing_score</td>";
        echo "<td>$weightage</td>";
        echo "<td>$attempt_no</td>";
        if ($score_flag == "Yes") {
            echo "<td>";
            echo $score;
            echo "</td>";
        }       
            $result = 'Awaited';        
        $result_bg = $result == "complete" ? "bg-green-2" : "bg-red-2";
        echo "<td><span class='text-11 rounded-16 text-blue-3 {$result_bg} py-5 px-5'>{$result}</span></td>";
        echo "</tr>";
    }else{
    $stmt_assemnt = $offering->get_assessment_score_card_complete_incomplete_all();
    while ($row_assemnt = $stmt_assemnt->fetch(PDO::FETCH_ASSOC)) {
        extract($row_assemnt);
        echo "<tr class='bg-white shadow-1 rounded-8 border-light'>";
        echo "<td>".htmlentities($assessment_name)."</td>";
        echo "<td>"
                . "<div class='about-content'>"
                  ."<div class='bg-green-2 about-content-list__icon'>"
                    ."<svg xmlns='http://www.w3.org/2000/svg' width='24'"
                      ." height='24' viewBox='0 0 24 24' fill='none'"
                       ."stroke='#000' stroke-width='2'"
                       ."stroke-linecap='round' stroke-linejoin='round'"
                       ."class='fa fa-check icon'>"
                      ."<polyline points='20 6 9 17 4 12'>"
                     ."</polyline>"
                    ."</svg>"
                 ."</div>"
            ."</div></td>";
        echo "<td><span class='text-11 rounded-16 text-black bg-blue-6 py-5 px-5'>"._("TB103")."</span></td>";
        echo "<td>$passing_score</td>";
        echo "<td>$weightage</td>";
        echo "<td>$attempt_no</td>";
        if ($score_flag == "Yes") {
            echo "<td>";
            echo $score;
            echo "</td>";
        }
        if ($score >= $passing_score) {
            $result = 'complete';
        } else {
            $result = 'incomplete';
        }
        $result_bg = $result == "complete" ? "bg-green-2" : "bg-red-2";
        echo "<td><span class='text-11 rounded-16 text-blue-3 {$result_bg} py-5 px-5'>{$result}</span></td>";
        echo "</tr>";
    }
}
}

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

