<?php 
/**
 * v2.1.0
 * shortcode: Result Page
 * status: completed
 */
add_shortcode('proqyz-result-page', 'shortcode_proqyz_result_page');
function shortcode_proqyz_result_page( $atts = [], $content = null, $tag = '' ) {
    
    $atts = array_change_key_case((array)$atts, CASE_LOWER);
    # override default attributes with user attributes
    $wporg_atts = shortcode_atts(
        array(
            'result_id' => null
        ) , $atts, $tag
    );

    if( $wporg_atts['result_id'] === null ) return '';
    $result_id = $wporg_atts['result_id'];

    global $wpdb, 
    $table_proqyz_v3_progress_submissions,
    $ST_OPTION_st_proqyz__result_message,
    $ST_OPTION_st_proqyz__result_message_gov_competitive_exam,
    $ST_OPTION_st_proqyz__result_message_pdf_quiz,
    $ST_OPTION_st_proqyz__result_message_ielts_reading_quiz,
    $ST_OPTION_st_proqyz__result_message_ielts_listening_quiz,
    $ST_OPTION_st_proqyz__result_message_ielts_writing_quiz,
    $ST_OPTION_st_proqyz__result_message_ielts_speaking_quiz;

    $single_result = $wpdb->get_row("SELECT `quiz_category` FROM {$table_proqyz_v3_progress_submissions} WHERE `ID` = '$result_id' LIMIT 1");
    $quiz_category = $single_result->quiz_category;

    $enable_custom_result               = get_option($ST_OPTION_st_proqyz__result_message,0);
    
    add_action('wp_enqueue_scripts', function() {
        global $wp_styles;
        
        // Loop through all registered styles
        foreach ($wp_styles->queue as $handle) {
            // Skip 'elementor-common' and dequeue others
            if ($handle !== 'elementor-common') {
                wp_dequeue_style($handle);
                wp_deregister_style($handle);
            }
        }
    }, 20);
    
    

    $result_message = '';
    if( $enable_custom_result == 1 ) {
        if( $quiz_category == "ielts-reading") {
            $reading_quiz_custom_result         = get_option($ST_OPTION_st_proqyz__result_message_ielts_reading_quiz,'');
            $reading_quiz_custom_result         = stripslashes($reading_quiz_custom_result);
            ob_start(); 
            if($reading_quiz_custom_result != '') { 
                add_filter('show_admin_bar', '__return_false');
                wp_head(); // Include the header.php file
            }
            ?><div id="content" style="width: 100%; padding: 0; margin: 0;">
                <?php echo do_shortcode($reading_quiz_custom_result); ?>
            </div><?php
            if($reading_quiz_custom_result != '') { 
                wp_footer();
            }
            $result_message = ob_get_clean();
        } else if( $quiz_category == "ielts-listening") {
            $listening_quiz_custom_result         = get_option($ST_OPTION_st_proqyz__result_message_ielts_listening_quiz,'');
            $listening_quiz_custom_result       = stripslashes($listening_quiz_custom_result);
            ob_start(); 
            if($listening_quiz_custom_result != '') { 
                add_filter('show_admin_bar', '__return_false');
                wp_head(); // Include the header.php file
            }
            ?><div id="content" style="width: 100%; padding: 0; margin: 0;">
                <?php echo do_shortcode($listening_quiz_custom_result); ?>
            </div><?php
            if($listening_quiz_custom_result != '') { 
                wp_footer();
            }
            $result_message = ob_get_clean();
        } else if( $quiz_category == "ielts-writing") {
            $writing_quiz_custom_result         = get_option($ST_OPTION_st_proqyz__result_message_ielts_writing_quiz,'');
            $writing_quiz_custom_result         = stripslashes($writing_quiz_custom_result);
            ob_start(); 
            if($writing_quiz_custom_result != '') { 
                add_filter('show_admin_bar', '__return_false');
                wp_head(); // Include the header.php file
            }
            ?><div id="content" style="width: 100%; padding: 0; margin: 0;">
                <?php echo do_shortcode($writing_quiz_custom_result); ?>
            </div><?php
            if($writing_quiz_custom_result != '') { 
                wp_footer();
            }
            $result_message = ob_get_clean();
        } else if( $quiz_category == "ielts-speaking") {
            $speaking_quiz_custom_result         = get_option($ST_OPTION_st_proqyz__result_message_ielts_speaking_quiz,'');
            $speaking_quiz_custom_result        = stripslashes($speaking_quiz_custom_result);
            ob_start(); 
            if($speaking_quiz_custom_result != '') { 
                add_filter('show_admin_bar', '__return_false');
                wp_head(); // Include the header.php file
            }
            ?><div id="content" style="width: 100%; padding: 0; margin: 0;">
                <?php echo do_shortcode($speaking_quiz_custom_result); ?>
            </div><?php
            if($speaking_quiz_custom_result != '') { 
                wp_footer();
            }
            $result_message = ob_get_clean();
        } else if( $quiz_category == "gov-non-sectional-timing" || $quiz_category == "gov-sectional-timing") {
            $competitive_exam_custom_result     = get_option($ST_OPTION_st_proqyz__result_message_gov_competitive_exam,'');
            $competitive_exam_custom_result     = stripslashes($competitive_exam_custom_result);
            ob_start(); 
            if($competitive_exam_custom_result != '') { 
                add_filter('show_admin_bar', '__return_false');
                wp_head(); // Include the header.php file
            }
            ?><div id="content" style="width: 100%; padding: 0; margin: 0;">
                <?php echo do_shortcode($competitive_exam_custom_result); ?>
            </div><?php
            if($competitive_exam_custom_result != '') { 
                wp_footer();
            }
            $result_message = ob_get_clean();
        } else if( $quiz_category == "proqyz-pdf-quiz") {
            $pdf_quiz_custom_result             = get_option($ST_OPTION_st_proqyz__result_message_pdf_quiz,'');
            $pdf_quiz_custom_result             = stripslashes($pdf_quiz_custom_result);
            ob_start(); 
            if($pdf_quiz_custom_result != '') { 
                add_filter('show_admin_bar', '__return_false');
                wp_head(); // Include the header.php file
            }
            ?><div id="content" style="width: 100%; padding: 0; margin: 0;">
                <?php echo do_shortcode($pdf_quiz_custom_result); ?>
            </div><?php
            if($pdf_quiz_custom_result != '') { 
                wp_footer();
            }
            $result_message = ob_get_clean();
        } 
    }

    return $result_message;

}