<?php session_start(); ?>
<div class="row ml-3 mr-3">

        <?php
        include '../config/database.php';
        include_once '../security/session_config.php';
        
        include_once "../config/properties.php";
        include_once "../resources/offering.php";
        
        // initialize objects
        $offering = new Offering();
        $id = $_SESSION['uid'];

        $badges = array();
        $coursename = array();
        $grade = array();

        $offering->user_id = $id;
        $offering->date = $date;

        $stmt = $offering->getoffers_achv();
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

            $offering->offering_id = $row['offering_id'];
            $offering->score = $row['score'];

            $stmt1 = $offering->getgrade_achv();
            while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) {
                if ($row1['grade_type'] != "Default") {

                    $offering->badge_id = $row1['badge_id'];
                    $stmt2 = $offering->getgrade_file_achv();
                    if ($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)) {

                        if ($row1['grade_type'] == "Gold") {
                            $grade_image = $row2['gold_file'];
                        } else if ($row1['grade_type'] == "Silver") {
                            $grade_image = $row2['silver_file'];
                        } else if ($row1['grade_type'] == "Bronze") {
                            $grade_image = $row2['bronze_file'];
                        }
                        $filepath = ADMIN_HTTP_PATH . $properties['jdbc.badge_folder'] . "/" . $row1['badge_id'] . "/" . $grade_image;
                        array_push($badges, $filepath);
                        array_push($coursename, htmlentities($row['course_name']));
                        array_push($grade, $row1['grade']);
                        break;
                    }
                }
            }
        }
        $count_array = count($badges);
	//$count_array = 0;
	$j=1;
        if ($count_array > 0) {
            for ($i = 0; $i < $count_array; $i++) {
               
                $limit = 0;
                while ($limit < 3) {

                    if (!empty($badges[$i])) {
                        echo "<div class='col-md-4 bg-white text-center box rounded-16' id='tr".$j."'>";
                        echo "<div class='col-md-12'>";
                            echo "<div class='achv_div mt-5'>";
                                echo "<img src='" . $badges[$i] . "'>";
                            echo "</div>";
                            echo "<p class='py-2 text-12 mb-0 border-bottom-dark'>".$grade[$i]."</p>";
                            echo "<h2 class='text-16 lh-12 mt-0 mb-0 py-5'>".htmlentities($coursename[$i])."</h2>";
                        echo '</div>';
                        echo '</div>';
                    }
                    $limit++;
                    $i++;
                }
                $i--;
                
		++$j;
            }
        } else {
            echo "<h4 class='text-center'>";
            echo _("HM0501");
            echo "</h4>";
        }
        ?> 
</div>
                                                