<?php 

function dynamic_css_imports() {
    $site_url = site_url();
    ob_start(); ?>
    <style>
                    @font-face {
                font-family: "Glyphicons Halflings";
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/glyphicons-halflings-regular.eot);
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/glyphicons-halflings-regular.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/glyphicons-halflings-regular.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/glyphicons-halflings-regular.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/glyphicons-halflings-regular.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular)
                    format("svg");
            }

            @font-face {
                font-family: "FontAwesome";
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.eot?v=4.7.0);
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.eot#iefix&v=4.7.0)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.woff2?v=4.7.0) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.woff?v=4.7.0) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.ttf?v=4.7.0) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular)
                    format("svg");
                font-weight: normal;
                font-style: normal;
            }

            @font-face {
                font-family: "Ionicons";
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/ionicons.eot?v=2.0.1);
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/ionicons.eot?v=2.0.1#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/ionicons.ttf?v=2.0.1) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/ionicons.woff?v=2.0.1) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/ionicons.svg?v=2.0.1#Ionicons) format("svg");
                font-weight: normal;
                font-style: normal;
            }

            @font-face {
                font-family: "FontAwesome";
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.eot);
                src: local("FontAwesome"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/fontawesome-webfont.svg#fontawesomeregular)
                    format("svg");
                font-weight: normal;
                font-style: normal;
                font-display: swap;
            }

            @font-face {
                font-family: "Nunito";
                font-style: normal;
                font-weight: 300;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-300.eot);
                src: local("Nunito Light"), local("Nunito-Light"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-300.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-300.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-300.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-300.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-300.svg#Nunito) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Nunito";
                font-style: normal;
                font-weight: 400;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-regular.eot);
                src: local("Nunito Regular"), local("Nunito-Regular"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-regular.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-regular.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-regular.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-regular.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-regular.svg#Nunito) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Nunito";
                font-style: italic;
                font-weight: 400;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-italic.eot);
                src: local("Nunito Italic"), local("Nunito-Italic"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-italic.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-italic.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-italic.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-italic.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-italic.svg#Nunito) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Nunito";
                font-style: normal;
                font-weight: 600;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-600.eot);
                src: local("Nunito SemiBold"), local("Nunito-SemiBold"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-600.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-600.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-600.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-600.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-600.svg#Nunito) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Nunito";
                font-style: normal;
                font-weight: 700;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-700.eot);
                src: local("Nunito Bold"), local("Nunito-Bold"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-700.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-700.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-700.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-700.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-700.svg#Nunito) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Nunito";
                font-style: normal;
                font-weight: 800;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-800.eot);
                src: local("Nunito ExtraBold"), local("Nunito-ExtraBold"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-800.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-800.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-800.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-800.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-800.svg#Nunito) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Nunito";
                font-style: normal;
                font-weight: 900;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-900.eot);
                src: local("Nunito Black"), local("Nunito-Black"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-900.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-900.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-900.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-900.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/nunito-v14-latin-900.svg#Nunito) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: normal;
                font-weight: 300;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-300.eot);
                src: local("Montserrat Light"), local("Montserrat-Light"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-300.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-300.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-300.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-300.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-300.svg#Montserrat) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: normal;
                font-weight: 400;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-regular.eot);
                src: local("Montserrat Regular"), local("Montserrat-Regular"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-regular.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-regular.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-regular.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-regular.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-regular.svg#Montserrat)
                    format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: normal;
                font-weight: 500;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-500.eot);
                src: local("Montserrat Medium"), local("Montserrat-Medium"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-500.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-500.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-500.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-500.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-500.svg#Montserrat) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: italic;
                font-weight: 400;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-italic.eot);
                src: local("Montserrat Italic"), local("Montserrat-Italic"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-italic.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-italic.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-italic.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-italic.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-italic.svg#Montserrat)
                    format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: normal;
                font-weight: 600;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-600.eot);
                src: local("Montserrat SemiBold"), local("Montserrat-SemiBold"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-600.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-600.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-600.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-600.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-600.svg#Montserrat) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: normal;
                font-weight: 700;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-700.eot);
                src: local("Montserrat Bold"), local("Montserrat-Bold"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-700.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-700.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-700.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-700.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-700.svg#Montserrat) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: normal;
                font-weight: 800;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-800.eot);
                src: local("Montserrat ExtraBold"), local("Montserrat-ExtraBold"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-800.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-800.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-800.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-800.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-800.svg#Montserrat) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "Montserrat";
                font-style: normal;
                font-weight: 900;
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-900.eot);
                src: local("Montserrat Black"), local("Montserrat-Black"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-900.eot#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-900.woff2) format("woff2"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-900.woff) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-900.ttf) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/montserrat-v15-latin-900.svg#Montserrat) format("svg");
                font-display: swap;
            }

            @font-face {
                font-family: "iot-fonts";
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/iot-fonts.eot?sex6nu=);
                src: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/iot-fonts.eot?sex6nu=#iefix)
                    format("embedded-opentype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/iot-fonts.ttf?sex6nu=) format("truetype"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/iot-fonts.woff?sex6nu=) format("woff"),
                    url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/fonts/iot-fonts.svg?sex6nu=#iot-fonts) format("svg");
                font-weight: normal;
                font-style: normal;
                font-display: block;
            }
    </style>
    <?php return ob_get_clean();
}

function proqyz_add_query_var_to_current_url( $key, $value ) {
    global $wp;
    // Get current full URL
    $current_url = home_url( add_query_arg( array(), $wp->request ) );
    
    // Append new query arg
    $new_url = add_query_arg( $key, $value, $current_url );
    
    return $new_url;
}


function get_lessons_by_id( $lessons = [], $lesson_id ) {
    if( count( $lessons ) > 0 ) {
        // filter the current lesson by given lesson id
        $filtered = array_filter($lessons, function($item) use ($lesson_id) {
            // Cast inner array to object
            $obj = (object) $item;
            // Cast details to object too
            $rest_lesson_id = $obj->_id;
            // echo $rest_lesson_id. "<br />"; debugger
            return isset($rest_lesson_id) && $rest_lesson_id == $lesson_id;
        });

        $filtered_lesson = array_values($filtered);
        if( count($filtered_lesson) > 0 ) {
            return $filtered_lesson[0];
        } else {
            return null;
        }

    } else {
        return null;
    }
}

function get_quiz_by_category( $quizzes = [], $quiz_category = "", $mock_test__course_id, $mock_test__lesson_id) {

    if(count($quizzes) <= 0 ) {
        return [
            "error" => true,
            "message" => "quizzes not found"
        ];
    }

    $filtered_quiz = array_filter($quizzes, function($item) use ($quiz_category) {
        // Cast inner array to object
        $obj = (object) $item;
        // Cast details to object too
        $rest_quiz_id = $obj->_id;
        $rest_quiz_type = $obj->_type;
        $rest_quiz_category = $obj->_category;
        return isset($rest_quiz_type) && $rest_quiz_type == "ielts" && isset($rest_quiz_category) && $rest_quiz_category == $quiz_category;
    });

    $filtered_quiz = array_values($filtered_quiz);
    if( count($filtered_quiz) <= 0 ) {
        return [
            "error" => true,
            "message" => "quiz not found"
        ];
    }

    $single_quiz = (object) $filtered_quiz[0];
    $quiz_id = $single_quiz->_id;
    $quiz_category = $single_quiz->_category;
    $quiz_type = $single_quiz->_type;

    # update - slug
    $attempt_url = st_proqyz_get_mock_test_quiz_url($mock_test__course_id, $mock_test__lesson_id, "$quiz_type-$quiz_category", $quiz_id);


    return [
        "status" => "success",
        "step" => $quiz_category,
        "quiz" => $single_quiz,
        "url"  => $attempt_url 
    ];
}

function steps($mock_test__course_id, $mock_test__lesson_id, $quizzes = []) {
    $current_step = "not-started";
    $current_user = wp_get_current_user();
    $get_full_test_meta = get_user_meta( $current_user->ID, "proqyz__full-mock-test--$mock_test__course_id-$mock_test__lesson_id", true);
    if( !$get_full_test_meta ) {

        // Basic user data
        $username   = $current_user->user_login;
        $email      = $current_user->user_email;
        $full_name  = trim( $current_user->first_name . ' ' . $current_user->last_name );
        // Custom fields (e.g., date of birth) - assuming saved in user meta
        $dob        = get_user_meta( $current_user->ID, 'dob', true );
        // Profile picture (WordPress uses Gravatar by default)
        $profile_pic_url = get_avatar_url( $current_user->ID, ['size' => 200] );
        
        ob_start(); ?>
        <div class="confirm-box step-guidance ">
            <h1 class="confirm-box__title">CONFIRM YOUR DETAILS</h1>
            <div class="confirm-box__contents-wrap">
                <div class="confirm-box__row">
                    <div class="confirm-box__col -name">Name:</div>
                    <div class="confirm-box__col -value"><?php echo $full_name? $full_name : 'XXXX XXXXX'; ?></div>
                </div>
                <div class="confirm-box__row">
                    <div class="confirm-box__col -name">Date of birth:</div>
                    <div class="confirm-box__col -value"><?php echo $dob? $dob  : 'XX/XX/XXXX'; ?></div>
                </div>
                <div class="confirm-box__row">
                    <div class="confirm-box__col -name">Your identity:</div>
                    <div class="confirm-box__col -value"><?php echo $email? $email : 'XXXXXXXXX'; ?></div>
                </div>
                <div class="confirm-box__row">
                    <div class="confirm-box__col -name">Candidate number:</div>
                    <div class="confirm-box__col -value"><?php echo $username? $username : 'XXXXX'; ?></div>
                </div>
            </div>
            <div class="confirm-box__footer"> 
                <a href="/collection/ielts-mock-test-2025-january" class="confirm-box__btn iot-grbt -white">
                <span class="ioticon-prev-icon"></span>Back
                </a> 
                <a href="javascript:;" class="confirm-box__btn btn-full-test__step-1 iot-grbt">
                My details are correct <span class="ioticon-next-icon"></span>
                </a>
            </div>
        </div>  
        <div class="instruction-box step-instruction hide">
            <h1 class="instruction-box__title">GENERAL INSTRUCTIONS</h1>
            <div class="instruction-box__caption">
                Watch the video below and confirm you completely understand before moving to the next step.
            </div>
            <video class="instruction-box__video" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/general_video.png" width="520" height="auto" controls="" controlslist="nodownload" webkit-playsinline="" playsinline="" disablepictureinpicture="">
                <source src="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/general-instructions.mp4" type="video/mp4">
                Your browser does not support the video tag. 
            </video>
            <a href="javascript:;" class="instruction-box__btn iot-grbt -disabled">
                <span class="ioticon-check-v2"></span>Confirm
            </a>
        </div>
        <div class="test-list step-4-skills hide">
        <h1 class="test-list__title">IELTS ACADEMIC TEST</h1>
        <div class="test-list__contents">
            <div class="test-card -listening -active">
                <h6 class="test-card__title">IELTS Listening Test</h6>
                <div class="test-card__caption"> Please watch the video guidance below and confirm you completely understand before taking the Listening test.</div>
                <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/listening.png" controls="" webkit-playsinline="" playsinline="">
                    <source src="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/listening.mp4" type="video/mp4">
                    Your browser does not support the video tag. 
                </video>
                <button data-title="Start the Listening test now" class="test-card__btn iot-grbt test-card__btn-skill -blue -disabled " data-href=""> Confirm </button>
            </div>
            <div class="test-card -reading -disabled">
                <h6 class="test-card__title">IELTS Reading Test</h6>
                <div class="test-card__caption"> Please watch the video guidance below and confirm you completely understand before taking the Reading test.</div>
                <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/reading.png"> Your browser does not support the video tag. </video>
                <button data-title="Start the Reading test now" class="test-card__btn iot-grbt test-card__btn-skill -green -disabled " data-href=""> Confirm </button>
            </div>
            <div class="test-card -writing -disabled">
                <h6 class="test-card__title">IELTS Writing Test</h6>
                <div class="test-card__caption"> Please watch the video guidance below and confirm you completely understand before taking the Writing test.</div>
                <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/writing.png"> Your browser does not support the video tag. </video>
                <button data-title="Start the Writing test now" class="test-card__btn iot-grbt test-card__btn-skill -orange -disabled " data-href=""> Confirm </button>
            </div>
            <div class="test-card -speaking -disabled">
                <h6 class="test-card__title">IELTS Speaking Test</h6>
                <div class="test-card__caption"> Please watch the video guidance below and confirm you completely understand before taking the Speaking test.</div>
                <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/speaking.png"> Your browser does not support the video tag. </video>
                <button data-title="Start the Speaking test now" class="test-card__btn iot-grbt test-card__btn-skill -pink -disabled " data-href=""> Confirm </button>
            </div>
        </div>
        </div>        
        <?php return ob_get_clean();
    } else {
        $get_full_test_meta = (object) $get_full_test_meta;
        $current_category = "listening";
        // update the session
        $listening_completed = false;
        $reading_completed = false;
        $writing_completed = false;
        $speaking_completed = false;

        if(isset($get_full_test_meta->status)) {
            if($get_full_test_meta->status === "not-started") {
                $current_step = "listening-start";
                $current_category = "listening";
            } else if($get_full_test_meta->status === "listening-completed--reading-start") {
                $current_step = "listening-completed--reading-start";
                $current_category = "reading";
                $listening_completed = true;
            } else if($get_full_test_meta->status === "reading-completed--writing-start") {
                $current_step = "reading-completed--writing-start";
                $listening_completed = true;
                $reading_completed = true;
                $current_category = "writing";
            } else if($get_full_test_meta->status === "writing-completed--speaking-start") {
                $current_step = "writing-completed--speaking-start";
                $listening_completed = true;
                $reading_completed = true;
                $writing_completed = true;
                $current_category = "speaking";
            } else if($get_full_test_meta->status === "speaking-completed--finish-test") {
                $current_step = "speaking-completed--finish-test";
                $current_category = "result";
                $listening_completed = true;
                $reading_completed = true;
                $writing_completed = true;
                $speaking_completed = true;
            } 
        } 

        // get quiz links
        $data_url = "";
        if($current_category === "result") {
            // $data_url = site_url() . "/proqyz/proqyz-course/$mock_test__course_id/$mock_test__lesson_id/simulation/result";
            # update - slug
            $data_url = st_proqyz_get_mock_test_url($mock_test__course_id, $mock_test__lesson_id, 'result');
        } else {
            $current_quiz_meta = (object) get_quiz_by_category($quizzes, $current_category, $mock_test__course_id, $mock_test__lesson_id);
            if( $current_quiz_meta->status == "success" ) {
                $data_url = $current_quiz_meta->url;
            }
        }

        // begin::final outputs
        ob_start();  ?>
        <div class="test-list step-4-skills">
            <h1 class="test-list__title">IELTS ACADEMIC TEST</h1>
            <div class="test-list__contents">

                <!-- Listening -->
                <div class="test-card -listening <?php
                    echo ($current_step === "not-started" || $current_step === "listening-start")
                        ? '-active'
                        : (
                            ($listening_completed)
                                ? '-completed -disabled'
                                : '-disabled'
                        );
                    ?>">
                    <h6 class="test-card__title">IELTS Listening Test</h6>
                    <div class="test-card__caption">Please watch the video guidance below and confirm you completely understand before taking the Listening test.</div>
                    <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/listening.png" <?php echo ($current_step == "not-started" || $current_step == "listening-start")? 'controls webkit-playsinline playsinline' : ''; ?>>
                        <?php if($current_step === "not-started" || $current_step === "listening-start"){ ?>
                            <source src="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/listening.mp4" type="video/mp4">
                        <?php } ?>
                        Your browser does not support the video tag.
                    </video>
                    <?php if($current_step === "listening-completed--reading-start"){ ?>
                        <button data-title="Start the Listening test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href=""> Completed </button>
                    <?php } else { ?>

                        <?php if($current_step == "listening-start" || $current_step == "not-started") { ?>
                            <button data-title="Start the Listening test now" class="test-card__btn iot-grbt test-card__btn-skill -blue -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } else if($listening_completed){ ?>
                            <button data-title="Start the Listening test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href=""> Completed </button>
                        <?php } else { ?>
                            <button data-title="Start the Listening test now" class="test-card__btn iot-grbt test-card__btn-skill -blue -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } ?>

                    <?php } ?>
                </div>

                <!-- Reading -->
                <div class="test-card -reading <?php
                    echo ($current_step === "listening-completed--reading-start")
                        ? '-active'
                        : (
                            ($reading_completed)
                                ? '-completed -disabled'
                                : '-disabled'
                        );
                    ?>">
                    <h6 class="test-card__title">IELTS Reading Test</h6>
                    <div class="test-card__caption">Please watch the video guidance below and confirm you completely understand before taking the Reading test.</div>
                    <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/reading.png" <?php echo ($current_step == "listening-completed--reading-start")? 'controls webkit-playsinline playsinline' : ''; ?>>
                        <?php if($current_step === "listening-completed--reading-start"){ ?>
                            <source src="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/reading.mp4" type="video/mp4">
                        <?php } ?>
                        Your browser does not support the video tag.
                    </video>
                    <?php if($current_step === "reading-completed--writing-start"){ ?>
                        <button data-title="Start the Reading test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href=""> Completed </button>
                    <?php } else { ?>

                        <?php if($current_step == "listening-completed--reading-start") { ?>
                            <button data-title="Start the Reading test now" class="test-card__btn iot-grbt test-card__btn-skill -green -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } else if($reading_completed){ ?>
                            <button data-title="Start the Reading test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href=""> Completed </button>
                        <?php } else { ?>
                            <button data-title="Start the Reading test now" class="test-card__btn iot-grbt test-card__btn-skill -blue -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } ?>

                    <?php } ?>
                </div>

                <!-- Writing -->
                <div class="test-card -writing <?php
                    echo ($current_step === "reading-completed--writing-start")
                        ? '-active'
                        : (
                            ($writing_completed)
                                ? '-completed -disabled'
                                : '-disabled'
                        );
                    ?>">
                    <h6 class="test-card__title">IELTS Writing Test</h6>
                    <div class="test-card__caption">Please watch the video guidance below and confirm you completely understand before taking the Writing test.</div>
                    <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/writing.png" <?php echo ($current_step == "reading-completed--writing-start")? 'controls webkit-playsinline playsinline' : ''; ?>>
                        <?php if($current_step === "reading-completed--writing-start"){ ?>
                            <source src="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/writing.mp4" type="video/mp4">
                        <?php } ?>
                        Your browser does not support the video tag.
                    </video>
                    <?php if($current_step === "writing-completed--speaking-start"){ ?>
                        <button data-title="Start the Writing test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href=""> Completed </button>
                    <?php } else { ?>

                        <?php if($current_step == "reading-completed--writing-start") { ?>
                            <button data-title="Start the Writing test now" class="test-card__btn iot-grbt test-card__btn-skill -orange -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } else if($writing_completed){ ?>
                            <button data-title="Start the Writing test now" class="test-card__btn iot-grbt test-card__btn-skill -white -disabled" data-href=""> Confirm </button>
                        <?php } else { ?>
                            <button data-title="Start the Writing test now" class="test-card__btn iot-grbt test-card__btn-skill -blue -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } ?>

                    <?php } ?>
                </div>

                <!-- Speaking -->
                <div class="test-card -speaking <?php
                    echo ($current_step === "writing-completed--speaking-start")
                        ? '-active'
                        : (
                            ($speaking_completed)
                                ? '-completed -disabled'
                                : '-disabled'
                        );
                    ?>">
                    <h6 class="test-card__title">IELTS Speaking Test</h6>
                    <div class="test-card__caption">Please watch the video guidance below and confirm you completely understand before taking the Speaking test.</div>
                    <video class="test-card__video" width="520" height="auto" poster="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/speaking.png" <?php echo ($current_step == "writing-completed--speaking-start")? 'controls webkit-playsinline playsinline' : ''; ?>>
                        <?php if($current_step === "writing-completed--speaking-start"){ ?>
                            <source src="https://<?php echo ST_CDN_ENDPOINT; ?>/ProQyz/public/speaking.mp4" type="video/mp4">
                        <?php } ?>
                        Your browser does not support the video tag.
                    </video>
                    <?php if($current_step === "speaking-completed--finish-test"){ ?>
                        <button data-title="Start the Speaking test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href=""> Completed </button>
                    <?php } else { ?>

                        <?php if($current_step == "writing-completed--speaking-start") { ?>
                            <button data-title="Start the Speaking test now" class="test-card__btn iot-grbt test-card__btn-skill -pink -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } else if($speaking_completed){ ?>
                            <button data-title="Start the Speaking test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href=""> Completed </button>
                        <?php } else { ?>
                            <button data-title="Start the Speaking test now" class="test-card__btn iot-grbt test-card__btn-skill -blue -disabled" data-href="<?php echo $data_url; ?>">Confirm</button>
                        <?php } ?>

                    <?php } ?>
                </div>

                <!-- Speaking -->
                <?php if($speaking_completed){ ?>
                <div class="test-card -result -active">
                    <h6 class="test-card__title">Full Mock Test Completed</h6>
                    <div class="test-card__caption">Please watch the video guidance below and confirm you completely understand before taking the Speaking test.</div>
                    <button data-title="Start the Speaking test now" class="test-card__btn iot-grbt test-card__btn-skill -white -completed" data-href="<?php echo $data_url; ?>"> Visit Result </button>

                </div>
                <?php } ?>

            </div>
        </div>
        <?php return ob_get_clean();
        // end::final outputs
    }
}

function get_fullmock_test_results( $mock_test__course_id, $mock_test__lesson_id, $current_user ) {
    $listening_html = ""; 
    $reading_html = ""; 
    $writing_html = ""; 
    $speaking_html = "";

    global $wpdb, 
    $table_proqyz_v3_progress_submissions, 
    $table_proqyz_v3_progress_submissions_meta,
    $table_proqyz_v3_progress_submissions_score;

    $get_results = $wpdb->get_results("SELECT `ID`, `quiz_category`, `review`, `api_id` FROM {$table_proqyz_v3_progress_submissions} WHERE 
        `session_type` = 'fresh' AND 
        `session_category` = 'fullmock-test' AND 
        `session_status` = 1 AND 
        `course_category` = 'proqyz-course' AND
        `course_id` = '$mock_test__course_id' AND
        `lesson_id` = '$mock_test__lesson_id' AND
        `quiz_category` IN ('ielts-listening','ielts-reading', 'ielts-writing', 'ielts-speaking') AND
        `user_id` = $current_user AND
        `status` = 1
    ");

    if(count($get_results) > 0 ) {
        foreach($get_results as $rkey => $record ) {
            $result_id          = $record->ID;
            $quiz_category      = $record->quiz_category;
            $review             = $record->review;
            $reviewed           = isset($review)? (int) $review : 0;
            $quiz_id            = $record->api_id;
            // get quiz meta from meta table here meta_key = 'quiz_slug' as serilized json
            $get_quiz_slug_meta      = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_progress_submissions_meta} WHERE `submission_id` = '$result_id' AND `meta_key` = 'quiz_slug' LIMIT 1");
            $quiz_slug              = $get_quiz_slug_meta->meta_value;
            // get quiz key

            // get course subcategory from meta table
            $get_course_subcategory_meta = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_progress_submissions_meta} WHERE `submission_id` = '$result_id' AND `meta_key` = 'course_subcategory' LIMIT 1");
            $course_subcategory = $get_course_subcategory_meta->meta_value;
            $course_subcategory = $course_subcategory ? $course_subcategory : 'academic';
            
            # update - slug
            $result_url         = st_proqyz_get_result_url( $quiz_category, $quiz_slug, $quiz_id, $result_id );
            if($quiz_category == "ielts-reading" || $quiz_category == "ielts-listening"){
                $score_db       = $wpdb->get_var("SELECT `score_data` FROM {$table_proqyz_v3_progress_submissions_score} WHERE `submission_id` = '$result_id' AND `user_id` = '$current_user' LIMIT 1");
                $score_json     = json_decode($score_db);
                $band = 2;
                $unit = "band";
                $finished = "";
                if (empty((array) $score_json)) {
                    $unit = "percentage";   
                    
                } else {
                    $total_questions = isset($score_json->total)? (int) $score_json->total : 0;
                    $total_correct   = isset($score_json->correct)? (int) $score_json->correct : 0;
                    $band            = ProQyz_Ielts_scoreToBand($total_correct, $course_subcategory);
                    $finished        = "-finished";
                }   

                if($quiz_category == "ielts-listening") {
                    if( $unit == "band" ) {
                        $data_pie = json_encode((object) [
                            "percent"       => 100,
                            "unit"          => $band,
                            "colorCircle"   => "#ECF8FA",
                            "colorSlice"    => "#33B2C7"
                        ]);
                    } else {
                        $data_pie = json_encode((object) [
                            "percent"       => 100,
                            "colorCircle"   => "#ECF8FA",
                            "colorSlice"    => "#33B2C7"
                        ]);
                    }

                    ob_start(); ?>
                    <div class="practice-item -blue">
                        <span class="practice-item__icon -listening"></span>
                        <h6 class="practice-item__title">Listening</h6>
                        <div class="practice-item__progress circular-progress <?php echo $finished; ?>" data-pie='<?php echo $data_pie; ?>' data-pie-index="1" style="width:64px;height:64px;">
                            
                        </div>
                        <a href="<?php echo $result_url; ?>" target="_blank" class="practice-item__btn iot-grbt -blue"> View detail<span class="ioticon-next-icon"></span></a>
                    </div>
                    <?php $listening_html = ob_get_clean();
                } else if($quiz_category == "ielts-reading") {
                    if( $unit === "band" ) {
                        $data_pie = json_encode((object) [
                            "percent"       => 100,
                            "unit"          => $band,
                            "colorCircle"   => "#ECF8FA",
                            "colorSlice"    => "#37854d"
                        ]);
                    } else {
                        $data_pie = json_encode((object) [
                            "percent"       => 100,
                            "colorCircle"   => "#ECF8FA",
                            "colorSlice"    => "#37854d"
                        ]);
                    }

                    ob_start(); ?>
                    <div class="practice-item -green">
                        <span class="practice-item__icon -reading"></span>
                        <h6 class="practice-item__title">Reading</h6>
                        <div class="practice-item__progress circular-progress <?php echo $finished; ?>" data-pie='<?php echo $data_pie; ?>' data-pie-index="2" style="width:64px;height:64px;">
                            
                        </div>
                        <a href="<?php echo $result_url; ?>" target="_blank" class="practice-item__btn iot-grbt -green"> View detail<span class="ioticon-next-icon"></span></a>
                    </div>
                    <?php $reading_html = ob_get_clean();
                }

            } else if($quiz_category == "ielts-writing" || $quiz_category == "ielts-speaking"){

                $overall_band   = 2;
                $finished = "";
                if( $quiz_category == "ielts-writing" ) {
                    $data_pie = json_encode((object) [
                        "percent"       => 100,
                        "colorCircle"   => "#ECF8FA",
                        "colorSlice"    => "#FAA859"
                    ]);
                } else if( $quiz_category == "ielts-speaking" ) {
                    $data_pie = json_encode((object) [
                        "percent"       => 100,
                        "colorCircle"   => "#ECF8FA",
                        "colorSlice"    => "#C86478"
                    ]);
                }

                if($reviewed == 1){
                    if($quiz_category == "ielts-writing"){
                        $scores = fullmock_get_scores_for_writing_and_speaking( $result_id, $current_user, $quiz_category );
                        if($scores['has_scores']){
                            $band = $scores['overall_score'];
                        }

                    } else if($quiz_category == "ielts-speaking"){
                        $scores = fullmock_get_scores_for_writing_and_speaking( $result_id, $current_user, $quiz_category );
                        if($scores['has_scores']){
                            $band = $scores['overall_score'];
                        }

                    }

                    $overall_band = $band; 
                    $finished     = "-finished";

                    if( $quiz_category == "ielts-writing" ) {
                        $data_pie = json_encode((object) [
                            "percent"       => 100,
                            "unit"          => $overall_band,
                            "colorCircle"   => "#ECF8FA",
                            "colorSlice"    => "#FAA859"
                        ]);

                            
                    } else if( $quiz_category == "ielts-speaking" ) {
                        $data_pie = json_encode((object) [
                            "percent"       => 100,
                            "unit"          => $overall_band,
                            "colorCircle"   => "#ECF8FA",
                            "colorSlice"    => "#C86478"
                        ]);
                    }
                      
                }

                if( $quiz_category == "ielts-writing" ) {
                    ob_start(); ?>
                    <div class="practice-item -orange">
                        <span class="practice-item__icon -writing"></span>
                        <h6 class="practice-item__title">Writing</h6>
                        <div class="practice-item__progress circular-progress <?php echo $finished; ?>" data-pie='<?php echo $data_pie; ?>' data-pie-index="3" style="width:64px;height:64px;">
                            
                        </div>
                        <a href="<?php echo $result_url; ?>" target="_blank" class="practice-item__btn iot-grbt -orange"> View detail<span class="ioticon-next-icon"></span></a>
                    </div>
                    <?php $writing_html = ob_get_clean();
                } else if( $quiz_category == "ielts-speaking" ) {
                    ob_start(); ?>
                    <div class="practice-item -pink">
                        <span class="practice-item__icon -speaking"></span>
                        <h6 class="practice-item__title">Speaking</h6>
                        <div class="practice-item__progress circular-progress <?php echo $finished; ?>" data-pie='<?php echo $data_pie; ?>' data-pie-index="4" style="width:64px;height:64px;">
                            
                        </div>
                        <a href="<?php echo $result_url; ?>" target="_blank" class="practice-item__btn iot-grbt -pink"> View detail<span class="ioticon-next-icon"></span></a>
                    </div>
                    <?php $speaking_html = ob_get_clean();
                }



            } 


        }
    }

    return (object) [
        "listening" => $listening_html,
        "reading"   => $reading_html,
        "writing"   => $writing_html,
        "speaking"  => $speaking_html
    ];
    
}

function reset_modals($course_id = "", $lesson_id = "", $child_id = "") {
    $remove_url = proqyz_add_query_var_to_current_url("reset_test", "true");
    if( $child_id !== "" && $child_id !== $student_id ) {
        $remove_url .= "&child_id=" . $child_id;
    }
    ob_start(); ?>
    
    <div class="modal fade modal-exit-test" id="modal-exit-test" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <i class="ioticon-x modal-exit-test__close-modal" data-dismiss="modal" aria-label="Close"></i>
                <div class="modal-body">
                    <div class="modal-exit-test__icon"></div>
                    <h4 class="modal-exit-test__title">Are you sure to exit the test?</h4>
                    <div class="modal-exit-test__desc">If you exit this test, you will lose all your previous answers and will need to take the entire test again.</div>
                    <div class="modal-exit-test__footer"> 
                        <button type="button" class="modal-exit-test__btn iot-grbt -white" data-dismiss="modal">Cancel</button> 
                        <a href="<?php echo $remove_url; ?>" class="modal-exit-test__btn iot-grbt -btn-exits-test" data-course="<?php echo $course_id; ?>" data-lesson="<?php echo $lesson_id; ?>">Yes</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade modal-exit-test" id="modal-reset-test" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <i class="ioticon-x modal-exit-test__close-modal" data-dismiss="modal" aria-label="Close"></i>
                <div class="modal-body">
                    <div class="modal-exit-test__icon"></div>
                    <h4 class="modal-exit-test__title">Are you sure to exit the test?</h4>
                    <div class="modal-exit-test__desc">If you exit this test, you will lose all your previous answers and will need to take the entire test again.</div>
                    <div class="modal-exit-test__footer"> 
                        <button type="button" class="modal-exit-test__btn iot-grbt -white" data-dismiss="modal">Cancel</button> 
                        <a href="<?php echo $remove_url; ?>" class="modal-exit-test__btn iot-grbt -btn-exits-test" data-course="<?php echo $course_id; ?>" data-lesson="<?php echo $lesson_id; ?>">Yes</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <?php return ob_get_clean(); 
}

/**
 * Helper function to delete speaking meta data including file deletion
 * 
 * @param int $session_id The session/submission ID
 * @return void
 */
function delete_speaking_meta_data($session_id) {
    global $wpdb, $table_proqyz_v3_progress_meta_submissions;

    // Get speaking meta from {$table_proqyz_v3_progress_meta_submissions}
    $get_speaking_meta = $wpdb->get_results($wpdb->prepare("
        SELECT `json`, `ID`
        FROM {$table_proqyz_v3_progress_meta_submissions}
        WHERE `session_id` = %d
    ", $session_id));

    if (count($get_speaking_meta) > 0) {
        $upload_dir  = wp_upload_dir();
        $upload_base = trailingslashit($upload_dir['basedir']); // absolute path to uploads

        foreach ($get_speaking_meta as $smrow) {
            $speaking_meta_id = (int) $smrow->ID;
            $speaking_meta_json = unserialize($smrow->json);

            // Handle file deletion for cpanel type recordings
            if (is_object($speaking_meta_json) && isset($speaking_meta_json->type) && $speaking_meta_json->type === "cpanel") {
                $relative_path = str_replace('wp-content/uploads/', '', ltrim($speaking_meta_json->location, '/'));
                $filepath = trailingslashit($upload_base . $relative_path) . $speaking_meta_json->filename;

                // Remove file if it exists and is writable
                if (file_exists($filepath) && is_writable($filepath)) {
                    @unlink($filepath);
                }
            }

            // Delete speaking meta record
            $wpdb->delete(
                $table_proqyz_v3_progress_meta_submissions,
                array('ID' => $speaking_meta_id),
                array('%d')
            );
        }
    }
}

/**
 * Helper function to delete quiz submission data (for listening, reading, writing)
 * 
 * @param int $submission_id The submission ID to delete
 * @param int $student_id The student/user ID
 * @return void
 */
function delete_quiz_submission_data($submission_id, $student_id) {
    global $wpdb,
        $table_proqyz_v3_progress_submissions_user_response,
        $table_proqyz_v3_progress_submissions_session,
        $table_proqyz_v3_progress_submissions_score,
        $table_proqyz_v3_submissions_evaluation_meta,
        $table_proqyz_v3_submissions_review,
        $table_proqyz_v3_submissions_review_meta,
        $table_proqyz_v3_submissions_versioning,
        $table_proqyz_v3_progress_submissions_meta,
        $table_proqyz_v3_progress_submissions;

    // Remove user response data
    $wpdb->delete($table_proqyz_v3_progress_submissions_user_response, array(
        'submission_id' => $submission_id
    ));

    // Remove session detail
    $wpdb->delete($table_proqyz_v3_progress_submissions_session, array(
        'submission_id' => $submission_id
    ));

    // Remove score
    $wpdb->delete($table_proqyz_v3_progress_submissions_score, array(
        'submission_id' => $submission_id
    ));

    // Remove evaluation meta
    $wpdb->delete($table_proqyz_v3_submissions_evaluation_meta, array(
        'session_id' => $submission_id
    ));

    // Remove review and review meta
    $get_reviews = $wpdb->get_results($wpdb->prepare("
        SELECT `ID`
        FROM {$table_proqyz_v3_submissions_review}
        WHERE `result_id` = %d
    ", $submission_id));

    if (count($get_reviews) > 0) {
        foreach ($get_reviews as $rrow) {
            $review_id = (int) $rrow->ID;
            $wpdb->delete($table_proqyz_v3_submissions_review_meta, array(
                'review_id' => $review_id
            ));
            $wpdb->delete($table_proqyz_v3_submissions_review, array(
                'ID' => $review_id
            ));
        }
    }

    // Get quiz_version_id and decrease usage_count
    $quiz_version_id = $wpdb->get_var($wpdb->prepare(
        "SELECT meta_value FROM {$table_proqyz_v3_progress_submissions_meta} WHERE submission_id = %d AND meta_key = 'quiz_version_id' LIMIT 1",
        $submission_id
    ));
    if ($quiz_version_id) {
        $current_count = $wpdb->get_var($wpdb->prepare(
            "SELECT usage_count FROM {$table_proqyz_v3_submissions_versioning} WHERE version_id = %d",
            $quiz_version_id
        ));
        $new_count = max($current_count - 1, 0);
        $wpdb->update(
            $table_proqyz_v3_submissions_versioning,
            array('usage_count' => $new_count),
            array('version_id' => $quiz_version_id),
            array('%d'),
            array('%d')
        );
    }

    // Delete submission meta
    $wpdb->delete($table_proqyz_v3_progress_submissions_meta, array(
        'submission_id' => $submission_id
    ));

    // Remove evaluation usermeta
    delete_user_meta($student_id, "st_proqyz__evaluation-{$submission_id}");

    // Remove main submission
    $wpdb->delete($table_proqyz_v3_progress_submissions, array(
        'ID' => $submission_id
    ));
}

function reset_fullmock_test($course_id = "", $lesson_id = "") {
    global $wpdb, 
		$table_proqyz_v3_progress_submissions, // main core submission entry table 
		$table_proqyz_v3_progress_submissions_meta,  // core submission meta table
		$table_proqyz_v3_progress_meta_submissions, // speaking submission meta table 
		$table_proqyz_v3_submissions_review, // review table
		$table_proqyz_v3_submissions_review_meta, // review meta table
		$table_proqyz_v3_submissions_versioning, // versioning table (quizzes)
		// v3 dedicated tables for json, session_detail, and score
		$table_proqyz_v3_progress_submissions_user_response, // user response table - json
		$table_proqyz_v3_progress_submissions_session, // session detail table - session_detail
		$table_proqyz_v3_progress_submissions_score, // score table - score
		// v3 submissions evaluation metadata table (usermeta-like for sessions)
		$table_proqyz_v3_submissions_evaluation_meta, // evaluation metadata table
		$table_proqyz_fullmock_tests_progress; // fullmock test sessions table (old)


    $current_user = wp_get_current_user();
    $student_id   = (int) $current_user->ID;
    $course_id    = sanitize_text_field( $course_id );
    $lesson_id    = sanitize_text_field( $lesson_id );
    
    // first get each quiz type result id from fullmock test progress table 
    $get_quiz_results = $wpdb->get_results( $wpdb->prepare("
        SELECT `ID`, `listening`, `reading`, `writing`, `speaking`
        FROM {$table_proqyz_fullmock_tests_progress}
        WHERE `status`   = 1
        AND `course_id`        = %s
        AND `lesson_id`        = %s
        AND `user_id`          = %d
    ", $course_id, $lesson_id, $student_id ) );

    // going to loop through each quiz type result id and delete the related data from the progress submissions and meta tables
    foreach($get_quiz_results as $qrow) {
        $listening_result_id = (int) $qrow->listening;
        $reading_result_id = (int) $qrow->reading;
        $writing_result_id = (int) $qrow->writing;
        $speaking_result_id = (int) $qrow->speaking;

        // Listening - use helper function
        $get_listening_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $listening_result_id));
        if ($get_listening_submission) {
            delete_quiz_submission_data((int) $get_listening_submission->ID, $student_id);
        }

        // Reading - use helper function
        $get_reading_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $reading_result_id));
        if ($get_reading_submission) {
            delete_quiz_submission_data((int) $get_reading_submission->ID, $student_id);
        }

        // Writing - use helper function
        $get_writing_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $writing_result_id));
        if ($get_writing_submission) {
            delete_quiz_submission_data((int) $get_writing_submission->ID, $student_id);
        }

        // Speaking - use helper function + handle speaking meta
        $get_speaking_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $speaking_result_id));
        if ($get_speaking_submission) {
            $speaking_submission_id = (int) $get_speaking_submission->ID;

            // Handle speaking meta from {$table_proqyz_v3_progress_meta_submissions}
            // This includes file deletion for speaking recordings
            delete_speaking_meta_data($speaking_submission_id);

            // Use helper function for standard deletion
            delete_quiz_submission_data($speaking_submission_id, $student_id);
        }

        // delete fullmock tests progress
        $wpdb->delete($table_proqyz_fullmock_tests_progress, array(
            'ID' => $qrow->ID
        ));
    }


    // more removal for unexpected tests attempts 
    // get all the sessions ids from {$table_proqyz_v3_progress_submissions} where course_id and lesson_id are the same as the given course_id and lesson_id and session_category is 'fullmock-test'
    $get_sessions = $wpdb->get_results($wpdb->prepare("
        SELECT `ID`, `quiz_category`
        FROM {$table_proqyz_v3_progress_submissions}
        WHERE `course_id` = %s
        AND `lesson_id` = %s
        AND `session_category` = 'fullmock-test'
        AND `session_status` = 1
        AND `user_id` = %d
    ", $course_id, $lesson_id, $student_id));
    if (count($get_sessions) > 0) {
        foreach ($get_sessions as $srow) {
            $session_id = (int) $srow->ID;

            // Handle speaking category with meta
            if ($srow->quiz_category === 'ielts-speaking') {
                // Handle speaking meta from {$table_proqyz_v3_progress_meta_submissions}
                delete_speaking_meta_data($session_id);
                delete_quiz_submission_data($session_id, $student_id);
            } else if (in_array($srow->quiz_category, array('ielts-listening', 'ielts-reading', 'ielts-writing'))) {
                // Use helper function for listening, reading, and writing
                delete_quiz_submission_data($session_id, $student_id);
            }
        }
    }


    // Delete user meta
    delete_user_meta( $student_id, "proqyz__full-mock-test--{$course_id}-{$lesson_id}" );
    $course_url = st_proqyz_get_course_url( $course_id );    
    wp_redirect( esc_url( $course_url ) );
    exit;
}

function reset_fullmock_test_as_admin($course_id = "", $lesson_id = "", $child_id = "") {
    global $wpdb,
        $table_proqyz_v3_progress_submissions, // main core submission entry table
        $table_proqyz_v3_progress_submissions_meta, // core submission meta table
        $table_proqyz_v3_progress_meta_submissions, // speaking submission meta table
        $table_proqyz_v3_submissions_review, // review table
        $table_proqyz_v3_submissions_review_meta, // review meta table
        $table_proqyz_v3_submissions_versioning, // versioning table (quizzes)
        // v3 dedicated tables for json, session_detail, and score
        $table_proqyz_v3_progress_submissions_user_response, // user response table - json
        $table_proqyz_v3_progress_submissions_session, // session detail table - session_detail
        $table_proqyz_v3_progress_submissions_score, // score table - score
        // v3 submissions evaluation metadata table (usermeta-like for sessions)
        $table_proqyz_v3_submissions_evaluation_meta, // evaluation metadata table
        $table_proqyz_fullmock_tests_progress; // fullmock test sessions table (old)


    // if its admin own result then below    
    $current_user = wp_get_current_user();
    $student_id   = (int) $current_user->ID;

    // if its student result then store students id from outside
    if( $child_id !== "" && $child_id !== $student_id ) {
        $student_id = (int) $child_id;
    }

    $course_id    = sanitize_text_field( $course_id );
    $lesson_id    = sanitize_text_field( $lesson_id );
    
    // first get each quiz type result id from fullmock test progress table 
    $get_quiz_results = $wpdb->get_results( $wpdb->prepare("
        SELECT `ID`, `listening`, `reading`, `writing`, `speaking`
        FROM {$table_proqyz_fullmock_tests_progress}
        WHERE `status`   = 1
        AND `course_id`        = %s
        AND `lesson_id`        = %s
        AND `user_id`          = %d
    ", $course_id, $lesson_id, $student_id ) );

    // going to loop through each quiz type result id and delete the related data from the progress submissions and meta tables
    foreach($get_quiz_results as $qrow) {
        $listening_result_id = (int) $qrow->listening;
        $reading_result_id = (int) $qrow->reading;
        $writing_result_id = (int) $qrow->writing;
        $speaking_result_id = (int) $qrow->speaking;

        // Listening - use helper function
        $get_listening_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $listening_result_id));
        if ($get_listening_submission) {
            delete_quiz_submission_data((int) $get_listening_submission->ID, $student_id);
        }

        // Reading - use helper function
        $get_reading_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $reading_result_id));
        if ($get_reading_submission) {
            delete_quiz_submission_data((int) $get_reading_submission->ID, $student_id);
        }

        // Writing - use helper function
        $get_writing_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $writing_result_id));
        if ($get_writing_submission) {
            delete_quiz_submission_data((int) $get_writing_submission->ID, $student_id);
        }

        // Speaking - use helper function + handle speaking meta
        $get_speaking_submission = $wpdb->get_row($wpdb->prepare("
            SELECT `ID`
            FROM {$table_proqyz_v3_progress_submissions}
            WHERE `ID` = %d
        ", $speaking_result_id));
        if ($get_speaking_submission) {
            $speaking_submission_id = (int) $get_speaking_submission->ID;

            // Handle speaking meta from {$table_proqyz_v3_progress_meta_submissions}
            // This includes file deletion for speaking recordings
            delete_speaking_meta_data($speaking_submission_id);

            // Use helper function for standard deletion
            delete_quiz_submission_data($speaking_submission_id, $student_id);
        }

        // delete fullmock tests progress
        $wpdb->delete($table_proqyz_fullmock_tests_progress, array(
            'ID' => $qrow->ID
        ));
    }


    // more removal for unexpected tests attempts 
    // get all the sessions ids from {$table_proqyz_v3_progress_submissions} where course_id and lesson_id are the same as the given course_id and lesson_id and session_category is 'fullmock-test'
    $get_sessions = $wpdb->get_results($wpdb->prepare("
        SELECT `ID`, `quiz_category`
        FROM {$table_proqyz_v3_progress_submissions}
        WHERE `course_id` = %s
        AND `lesson_id` = %s
        AND `session_category` = 'fullmock-test'
        AND `session_status` = 1
        AND `user_id` = %d
    ", $course_id, $lesson_id, $student_id));
    if (count($get_sessions) > 0) {
        foreach ($get_sessions as $srow) {
            $session_id = (int) $srow->ID;

            // Handle speaking category with meta
            if ($srow->quiz_category === 'ielts-speaking') {
                // Handle speaking meta from {$table_proqyz_v3_progress_meta_submissions}
                delete_speaking_meta_data($session_id);
                delete_quiz_submission_data($session_id, $student_id);
            } else if (in_array($srow->quiz_category, array('ielts-listening', 'ielts-reading', 'ielts-writing'))) {
                // Use helper function for listening, reading, and writing
                delete_quiz_submission_data($session_id, $student_id);
            }
        }
    }


    // Delete user meta
    delete_user_meta( $student_id, "proqyz__full-mock-test--{$course_id}-{$lesson_id}" );
    $course_url = st_proqyz_get_course_url( $course_id );    
    wp_redirect( esc_url( $course_url ) );
    exit;
}

function fullmock_test_normalize_user_role( $roles ) {
    // Handle empty roles
    if ( empty( $roles ) || ! is_array( $roles ) ) {
        return 'student';
    }
    
    // Check for admin role first (highest priority)
    if ( in_array( 'administrator', $roles, true ) ) {
        return 'admin';
    }
    
    // Define teacher-equivalent roles
    $teacher_roles = array( 'instructor', 'teacher', 'trainer' );
    
    // Check if user has any teacher role
    foreach ( $roles as $role ) {
        if ( in_array( strtolower( $role ), $teacher_roles, true ) ) {
            return 'teacher';
        }
    }
    
    // Default to student for all other roles
    return 'student';
}

/**
 * helper function to get score from review and review meta using result id, user id
 */
function fullmock_get_scores_for_writing_and_speaking( $result_id, $user_id, $quiz_category ) {
    global $wpdb, $table_proqyz_v3_submissions_review, $table_proqyz_v3_submissions_review_meta, $table_proqyz_v3_progress_submissions_meta;
    if($quiz_category === "ielts-writing"){
        // get sections from meta table using result id
        $sections = $wpdb->get_var( $wpdb->prepare(
            "SELECT meta_value FROM {$table_proqyz_v3_progress_submissions_meta} 
            WHERE submission_id = %d AND meta_key = 'sections' LIMIT 1",
            $result_id
        ) );
        $sections = @unserialize( $sections );
        $sections = ! empty( $sections ) ? (array) $sections : array();
        // checking for task 1 and task 2 
        $has_task_1 = false;
        $task_1_id = null;
        $has_task_2 = false;
        $task_2_id = null;
        // writing tasks related logic here
        if( count( $sections ) > 0 ) {
            foreach( $sections as $section ) {
                $section = (object) $section;
                if( isset( $section->order ) ) {
                    if( $section->order == 1 ) {
                        $has_task_1 = true;
                        $task_1_id = $section->_id;
                    } else if( $section->order == 2 ) {
                        $has_task_2 = true;
                        $task_2_id = $section->_id;
                    }
                }
            }
        }

        // now get score for task 1 and task 2
        $task_1_score = 0;
        $task_2_score = 0;
        $overall_score = 0;
        $has_scores = true;
        # get score from review-scores meta from review meta table using (result_id & section_id )
        $task1_scores = fullmock_get_writing_review_score_from_review_and_review_meta( $result_id, $task_1_id, $user_id );
        $task2_scores = fullmock_get_writing_review_score_from_review_and_review_meta( $result_id, $task_2_id, $user_id );
        if( $task1_scores ) {
            # if task 1 score is not null when means its returning array of scores example: [0,0,0,0]
            $task_1_score_arr = $task1_scores;
            $task_1_score = array_sum( $task_1_score_arr ) / 4;
            $task_1_score = round( $task_1_score * 2 ) / 2;
        } else {
            $has_scores = false;
        }

        if( $task2_scores ) {
            # if task 2 score is not null when means its returning array of scores example: [0,0,0,0]
            $task_2_score_arr = $task2_scores;
            $task_2_score = array_sum( $task_2_score_arr ) / 4;
            $task_2_score = round( $task_2_score * 2 ) / 2;
        } else {
            $has_scores = false;
        }


        if($has_scores) {
            $overall_score = ($task_1_score + $task_2_score) / 2;
            $overall_score = round( $overall_score * 2 ) / 2;
        }

        return array(
            'task_1_score' => $task_1_score,
            'task_2_score' => $task_2_score,
            'overall_score' => $overall_score,
            'has_scores' => $has_scores
        );

    } else if($quiz_category === "ielts-speaking") {
        $scores = fullmock_get_speaking_review_score_from_review_and_review_meta( $result_id, $user_id);
        if( $scores ) {
            $task_score_arr = $scores;
            $task_score = array_sum( $task_score_arr ) / 4;
            $task_score = round( $task_score * 2 );
            $overall_score = $task_score/2;

            return array(
                'overall_score' => $overall_score,
                'has_scores' => true
            );
        }  else {
            return array(
                'overall_score' => 0,
                'has_scores' => false
            );
        }
    }
}

function fullmock_get_writing_review_score_from_review_and_review_meta( $submission_id, $section_id, $user_id ) {
    global $wpdb, $table_proqyz_v3_submissions_review, $table_proqyz_v3_submissions_review_meta;
    $review_id = $wpdb->get_var( $wpdb->prepare(
        "SELECT `ID` FROM {$table_proqyz_v3_submissions_review} 
        WHERE `result_id` = %d AND `section_id` = %s AND `user_id` = %d AND `status` = 1 LIMIT 1",
        $submission_id,
        $section_id,
        $user_id
    ) );

    if( $review_id ) {
        $review_scores = $wpdb->get_var( $wpdb->prepare(
            "SELECT meta_value FROM {$table_proqyz_v3_submissions_review_meta} 
            WHERE `review_id` = %d AND `meta_key` = 'review-scores' LIMIT 1",
            $review_id
        ) );
        if( $review_scores ) {
            $review_scores_json = json_decode( $review_scores, true );
            return $review_scores_json;
        }
    }
    return null;
}

function fullmock_get_speaking_review_score_from_review_and_review_meta( $result_id, $user_id ) {
    global $wpdb, $table_proqyz_v3_submissions_review, $table_proqyz_v3_submissions_review_meta;
    $review_id = $wpdb->get_var( $wpdb->prepare(
        "SELECT `ID` FROM {$table_proqyz_v3_submissions_review} 
        WHERE `result_id` = %d AND `user_id` = %d AND `status` = 1 LIMIT 1",
        $result_id,
        $user_id
    ) );
    if( $review_id ) {
        $review_scores = $wpdb->get_var( $wpdb->prepare(
            "SELECT meta_value FROM {$table_proqyz_v3_submissions_review_meta} 
            WHERE `review_id` = %d AND `meta_key` = 'review-scores' LIMIT 1",
            $review_id
        ) );
        if( $review_scores ) {
            $review_scores_json = json_decode( $review_scores, true );
            return $review_scores_json;
        }
    }

    return null;
}


