<?php 
/**
 * v3.1.0
 * status: completed
 * class Questions
 */
class Questions{
    public static $current_q_index  = 0;
    public static $q_counter        = 0;
    public static $rq_counter       = 0;
    public static $pallete          = '';
    
    public $user_response           = null;
    public $is_resume               = false;
    public $is_result               = false;
    public $is_loc                  = false;

    public static $total_correct    = 0;
    public static $total_wrong      = 0;
    public static $total_attempt    = 0;
    public static $total_unattempt  = 0;
    public static $question_types   = [];
    public $is_report               = true;
    public static $question_qt      = [];

    public function __construct(){ }

    public function get_char($index = 0) {
        $chars = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
        return isset($chars[$index])? $chars[$index] : $index;
    }

    public function str_replace_first($search, $replace, $subject){
        $search = '/'.preg_quote($search, '/').'/';
        return preg_replace($search, $replace, $subject, 1);
    }


    # checking - completed - working
    public function question_type_fillup($pindex, $question = []){
        // main question
        $question               = (object) $question;
        $question_id            = isset($question->_id)? $question->_id : '';
        $section_id             = isset($question->_postId)? $question->_postId : '';
        $_questionSettings      = isset($question->_questionSettings)? (object) $question->_questionSettings : (object) [];
        $input_type             = isset($_questionSettings->inputType)? (string) $_questionSettings->inputType : null;
        $question_content       = isset($question->content)? (object) $question->content : (object) [];
        $html                   = isset($question_content->html)? (string) $question_content->html : "empty";
        $explanations           = isset($question->explanations)? (array) $question->explanations : (array) [];
        $groupListenSettings    = isset($_questionSettings->audioTime)? (object) $_questionSettings->audioTime : (object) [ "status" => false, "time" => 0 ];
        
        
        $number_of_questions    = 0;
        $TYPE                   = "";

        # regex check
        if(preg_match_all( '/\{([^{}]+)\}/', $html, $multiTextMatches)){
            $matches                = $multiTextMatches[0];
            $number_of_questions    = (int) count($matches);   
        }

        $q_total_questions      = (int) $number_of_questions;
        $headings               = "";
        $before_q               = self::$q_counter + 1;
        $show_overall           = $q_total_questions;
        $notice                 = '';
        $explanations_html      = "";

        if(preg_match_all( '/\{([^{}]+)\}/', $html, $multiTextMatches)){
            // {}
            $matches        = $multiTextMatches[0];
            $inner_values   = $multiTextMatches[1];
            if( $number_of_questions == count($explanations)){

                for($i = 0; $i < $number_of_questions; $i++ ) {
                    self::$q_counter++;

                    $expression     = $matches[$i];
                    $inner_value    = $inner_values[$i];
                    $inner_arr      = (array) explode("|", $inner_value );
                    $inner_arr      = array_map(function($value) {
                        return html_entity_decode(strip_tags(trim(strtolower($value))));
                    }, $inner_arr);
                    $inner_arr_un   = $inner_arr;


                    # update for listen from here
                    $explanation    = isset($explanations[$i])? $explanations[$i] : (object) [ "html" => null, "istenFromHere" => (object) [
                        "status" => false,
                        "time"   => 0   
                    ] ];

                    # listen from here
                    $question_listenFromHere_html = '';
                    if(isset($explanation->listenFromHere)){
                        $listenFromHere = (object) $explanation->listenFromHere;
                        if( isset($listenFromHere->status) && $listenFromHere->status ) {
                            if(isset($listenFromHere->time)) {
                                ob_start(); ?>
                                <a href="javascript:void(0)" class="proqyz-lfh" data-time="<?php echo $listenFromHere->time; ?>">
                                    <span class="icon-listen"></span>
                                    Listen from here
                                </a>
                                <?php $question_listenFromHere_html = ob_get_clean();
                            }
                        }  
                    }  



                    // Apply the same transformations to each element in the array
                    $inner_arr = array_map(function($value) {
                        return html_entity_decode(strip_tags(trim(strtolower($value))));
                    }, $inner_arr);


                
                    $fill_answer = false;
                    $user_answer = "";
                    $is_correct     = true;
                    $c_class        = '';
                    $qp_class       = '';
                    $exp_html       = '';


                    /**
                     * Result logic | resume logic
                     */
                    if( $this->is_result || $this->is_resume) {
                        $response       = (object) $this->user_response;
                        $quiz_details   = isset($response->quiz)? (object) $response->quiz : null;
                        $user_answers   = isset($response->answers)? (array) $response->answers : null;
                        
                        $current_question = isset($user_answers[self::$q_counter])? (object) $user_answers[self::$q_counter] : null;
                        if( $current_question ) {
                            $input_type     = isset($current_question->input_type)? $current_question->input_type : '';
                            $q_type         = isset($current_question->q_type)? $current_question->q_type : ''; 
                            $input_class    = isset($current_question->class)? $current_question->class : ''; 
                            $q_total        = isset($current_question->total)? (int) $current_question->total : 0;

                            if( $q_total == (int) $q_total_questions &&  $input_type == "fillup" && $q_type == $TYPE && $input_class == "-checked" ) {
                                $fill_answer = true;
                                $user_answer = isset($current_question->answer)? $current_question->answer : '';
                            }
                            
                        }
                        
                    }

                    /**
                     * answer logic
                     */
                    if($fill_answer) {
                        self::$total_attempt++;
                        if (in_array(strtolower(trim($user_answer)), $inner_arr)) {
                            self::$total_correct++;
                            $c_class = '-attempt -correct -correct-fillup';
                            $qp_class = '-qp-attempt -qp-correct';
                            self::$question_types[self::$q_counter] = (object) [
                                "q_type"        => $TYPE,
                                "q_input_type"  => "fillup",
                                "q_p_index"     => $pindex+1,
                                "q_index"       => self::$q_counter,
                                "status"        => "correct"    
                            ];
                        } else {
                            self::$total_wrong++;
                            $c_class = '-attempt -wrong -wrong-fillup';
                            $qp_class = '-qp-attempt -qp-wrong';
                            self::$question_types[self::$q_counter] = (object) [
                                "q_type"        => $TYPE,
                                "q_input_type"  => "fillup",
                                "q_p_index"     => $pindex+1,
                                "q_index"       => self::$q_counter,
                                "status"        => "wrong"    
                            ];
                        }
                    } else {
                        self::$total_unattempt++;
                        $c_class = '-unattempt';
                        $qp_class = '-qp-unattempt';
                        self::$question_types[self::$q_counter] = (object) [
                            "q_type"        => $TYPE,
                            "q_input_type"  => "fillup",
                            "q_p_index"     => $pindex+1,
                            "q_index"       => self::$q_counter,
                            "status"        => "unattempt"    
                        ];
                    }

                    self::$question_qt[] = (object) [
                        "_id"           => $question_id,
                        "counter"       => self::$q_counter,
                        "type"          => $input_type,
                        "section_id"    => $section_id
                    ];
                                    

                    if($this->is_result){ ob_start(); ?>
                        <li class="answer">
                            <span>
                                <b><?php echo self::$q_counter; ?></b>
                            </span> 
                            Answer: <span class="b-r"><?php echo implode("<b style='color:black;'> | </b>", $inner_arr_un); ?></span>
                            <div class="sl-item explanation">
                                <div class="sl-control"> 
                                    <a class="explanation-click" title="Explain" data-toggle="collapse" data-target="#col-<?php echo self::$q_counter; ?>" href="javascript:void(0)"> 
                                        <span class="icon-explain"></span> Explain 
                                    </a> 
                                    <?php if($this->is_loc){ ?>
                                    <a class="locate-explain" data-q="<?php echo self::$q_counter; ?>" title="Locate" href="javascript:void(0)"> 
                                        <span class="icon-locale"></span> Locate 
                                    </a>   
                                    <?php } ?>
                                    <?php echo $question_listenFromHere_html; ?>

                                    <!--begin::report-->
                                    <?php if($this->is_report){ ?>
                                    <a 
                                        data-q_id="<?php echo $question_id; ?>" 
                                        data-q_type="fillup" 
                                        data-s_id="<?php echo $section_id; ?>" 
                                        data-q_item="<?php echo self::$q_counter; ?>" 
                                        class="locate-explain hide-mobile use-ajax"
                                        data-type="question-report"
                                    >
                                        <i class="fa fa-exclamation-triangle"></i>
                                        Report
                                    </a>
                                    <?php } ?>
                                    <!--end::report-->

                                    

                                </div>
                                <div id="col-<?php echo self::$q_counter; ?>" class="collapse">
                                    <div align="left" dir="ltr" style="margin-left:-7px">
                                        <?php 
                                            
                                            if(isset($explanation->html) && $explanation->html !== null){ 
                                                if(!empty($explanation->html)){
                                                    echo $explanation->html;
                                                } else {
                                                    echo "Correct answer is: ".implode("<b style='color:black;'> | </b>", $inner_arr_un); 
                                                }
                                            } else { 
                                                echo "Correct answer is: ".implode("<b style='color:black;'> | </b>", $inner_arr_un);
                                            }
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </li>
                    <?php $exp_html = ob_get_clean(); }

                    // main select input
                    ob_start(); ?>
                        <span style="display:none;" class="qp-item <?php echo $qp_class; ?>"><?php echo self::$q_counter; ?></span>
                        <input 
                            
                            type="text" 
                            placeholder="<?php echo self::$q_counter; ?>" 
                            class="question__input iot-question iot-lr-question iot-question__fill-blank form-control test-panel__input-answer <?php echo $c_class; ?>" 
                            data-q_type="<?php echo $TYPE; ?>"
                            data-input_type="fillup"
                            data-num="<?php echo self::$q_counter; ?>"
                            data-id="q-<?php echo self::$q_counter; ?>"
                            data-part="<?php echo $pindex+1; ?>"
                            data-q_total="<?php echo $q_total_questions; ?>"
                            autocomplete="off" 
                            id="q-<?php echo self::$q_counter; ?>"
                            value="<?php echo ($fill_answer)? $user_answer : ''; ?>"
                        >
                    <?php $input_fillup = ob_get_clean();

                    
                    $explanations_html .= $exp_html;
                    $html = $this->str_replace_first($expression,$input_fillup,$html);

                    
                }
            } else {
                $notice .= "It Looks like Question and Explanations are not available as the same amount";
            }

        }

        if($show_overall > 0){

            $group_listenFromHere_html = '';
            if( isset($groupListenSettings->status) && $groupListenSettings->status ) {
                if(isset($groupListenSettings->time)) {
                    ob_start(); ?>
                    <span class="listen-from-here proqyz-lfh" data-time="<?php echo $groupListenSettings->time; ?>">Listen from here</span>
                    <?php $group_listenFromHere_html = ob_get_clean();
                }
            }

            if ($q_total_questions > 1) {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        Questions <?php echo $before_q; ?>-<?php echo self::$q_counter; ?>
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                    <div class="test-panel__question-desc"></div>
                </div>
                <?php $headings = ob_get_clean();
            } else {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        Question <?php echo $before_q; ?>
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                    <div class="test-panel__question-desc"></div>
                </div>
                <?php $headings = ob_get_clean();
            }
        } else {
            $html = '';
        }

        return (object) ["html" => $html, "headings" => $headings, "explanations" => $explanations_html, "notice" => $notice ];
    }

    # checking - completed - working
    public function question_type_select($pindex, $question = []){
        // main question
        $question_html          = "";
        $question               = (object) $question;
        $question_id            = isset($question->_id)? $question->_id : '';
        $section_id             = isset($question->_postId)? $question->_postId : '';
        $_questionSettings      = isset($question->_questionSettings)? (object) $question->_questionSettings : (object) [];
        $input_type             = isset($_questionSettings->inputType)? (string) $_questionSettings->inputType : null;
        $_answerSettings        = isset($question->_answerSettings)? (object) $question->_answerSettings : (object) [];
        $number_of_options      = isset($_answerSettings->numberOfOptions)? (int) $_answerSettings->numberOfOptions : 0;
        $answerType             = isset($_answerSettings->answerType)? (string) $_answerSettings->answerType : null;
        $answerTypes            = isset($_answerSettings->answerTypes)? (array) $_answerSettings->answerTypes : (array) [];
        $explanations           = isset($question->explanations)? (array) $question->explanations : (array) [];
        $question_content       = isset($question->content)? (object) $question->content : (object) [];
        $html                   = isset($question_content->html)? (string) $question_content->html : "empty";
        $groupListenSettings    = isset($_questionSettings->audioTime)? (object) $_questionSettings->audioTime : (object) [ "status" => false, "time" => 0 ];
        
        
        $TYPE                   = "";
        $number_of_questions    = 0;

        # if its select then get regex {}
        if(preg_match_all( '/\{([^{}]+)\}/', $html, $multiTextMatches)){
            $matches                = $multiTextMatches[0];
            $inner_values           = $multiTextMatches[1];
            foreach( $inner_values as $ikey => $value ) {
                // A - $value
                if(isset($answerTypes[$answerType])){
                    if(in_array($value, (array) $answerTypes[$answerType] )) {
                        $number_of_questions++;
                    }
                }
            }

            
        }

        $q_total_questions  =  (int) $number_of_questions;

        $before_q           = self::$q_counter + 1;
        $headings           = '';
        $show_overall       = $number_of_questions;
        $explanations_html  = "";
        $notice             = "";
        $selectedOptions    = [];
        if($answerTypes[$answerType]){
            $selectedOptions = (array) array_slice($answerTypes[$answerType], 0, $number_of_options);
        }

        if(preg_match_all( '/\{([^{}]+)\}/', $html, $multiTextMatches)){
            // {}
            $matches        = $multiTextMatches[0];
            $inner_values   = $multiTextMatches[1];

            if( $number_of_questions == count($explanations)){
                for($i = 0; $i < $number_of_questions; $i++ ) {
                    $expression         = $matches[$i];
                    $before_q_c         = self::$q_counter;
                    // $explanation        = isset($explanations[$i])? $explanations[$i] : (object) [ "html" => null ];
                    $explanation        = isset($explanations[$i])? $explanations[$i] : (object) [ "html" => null, "istenFromHere" => (object) [
                        "status" => false,
                        "time"   => 0   
                    ] ];

                    $question_listenFromHere_html = '';
                    if(isset($explanation->listenFromHere)){
                        $listenFromHere = (object) $explanation->listenFromHere;
                        if( isset($listenFromHere->status) && $listenFromHere->status ) {
                            if(isset($listenFromHere->time)) {
                                ob_start(); ?>
                                <a href="javascript:void(0)" class="proqyz-lfh" data-time="<?php echo $listenFromHere->time; ?>">
                                    <span class="icon-listen"></span>
                                    Listen from here
                                </a>
                                <?php $question_listenFromHere_html = ob_get_clean();
                            }
                        }  
                    }    


                    self::$q_counter++;

                    /**
                     * Resume logic - Result Logic
                     */
                    $fill_answer    = false;
                    $user_answer    = "";
                    $is_correct     = false;
                    $c_class        = '';
                    $qp_class       = '';
                    $correct_answer = '';

                    /**
                     * Result logic
                     */
                    if( $this->is_result || $this->is_resume ) {
                        $response       = (object) $this->user_response;
                        $quiz_details   = isset($response->quiz)? (object) $response->quiz : null;
                        $user_answers   = isset($response->answers)? (array) $response->answers : null;
                        
                        $current_question = isset($user_answers[self::$q_counter])? (object) $user_answers[self::$q_counter] : null;
                        if( $current_question ) {
                            $input_type     = isset($current_question->input_type)? $current_question->input_type : '';
                            $q_type         = isset($current_question->q_type)? $current_question->q_type : ''; 
                            $input_class    = isset($current_question->class)? $current_question->class : ''; 
                            $q_total        = isset($current_question->total)? (int) $current_question->total : 0;
                            

                            if( $q_total == (int) $q_total_questions &&  $input_type == "select" && $q_type == $TYPE && $input_class == "-checked" ) {
                                $fill_answer = true;
                                $user_answer = isset($current_question->answer)? $current_question->answer : '';
                            } 
                        }
                        
                    }


                    # options
                    ob_start();
                    foreach( $selectedOptions as $okey => $option){ 
                        if($option == $inner_values[$i]){
                            $correct_answer = $option;
                        }
                        # check answer logic
                        if( $fill_answer && $user_answer == $option && $option == $inner_values[$i] ) {
                            $is_correct = true;
                        }

                        ?>
                        <option value="<?php echo $option; ?>" <?php echo ($fill_answer && $user_answer == $option)? 'selected' : ''; ?>><?php echo $option; ?></option>
                        <?php 
                    }
                    $options = ob_get_clean();


                    // final result report for each question
                    if( $fill_answer){
                        self::$total_attempt++;
                        if( $is_correct ) {
                            self::$total_correct++;
                            $c_class = '-attempt -correct -correct-select';
                            $qp_class = '-qp-attempt -qp-correct';
                            self::$question_types[self::$q_counter] = (object) [
                                "q_type"        => $TYPE,
                                "q_input_type"  => "select",
                                "q_p_index"     => $pindex+1,
                                "q_index"       => self::$q_counter,
                                "status"        => "correct"    
                            ];
                        } else {
                            self::$total_wrong++;
                            $c_class = '-attempt -wrong -wrong-select';
                            $qp_class = '-qp-attempt -qp-wrong';
                            self::$question_types[self::$q_counter] = (object) [
                                "q_type"        => $TYPE,
                                "q_input_type"  => "select",
                                "q_p_index"     => $pindex+1,
                                "q_index"       => self::$q_counter,
                                "status"        => "wrong"    
                            ];
                        }
                    } else {
                        self::$total_unattempt++;
                        $c_class = '-unattempt';
                        $qp_class = '-qp-unattempt';
                        self::$question_types[self::$q_counter] = (object) [
                            "q_type"        => $TYPE,
                            "q_input_type"  => "select",
                            "q_p_index"     => $pindex+1,
                            "q_index"       => self::$q_counter,
                            "status"        => "unattempt"    
                        ];
                    }
                    
                    if(!$this->is_result){
                        $c_class = '';
                        $qp_class = '';
                    }

                    // main select input
                    ob_start(); ?>
                    <span style="" class="qp-item <?php echo $qp_class; ?>"><?php echo self::$q_counter; ?></span>
                    <select 
                        value="" 
                        data-q_type="<?php echo $TYPE; ?>"
                        data-input_type="select"
                        data-num="<?php echo self::$q_counter; ?>"
                        data-id="q-<?php echo self::$q_counter; ?>"
                        data-part="<?php echo $pindex+1; ?>"
                        data-q_total="<?php echo $q_total_questions; ?>"
                        class="question__input iot-lr-question iot-option iot-dropdown form-control mb-2 <?php echo $c_class; ?>"
                    >
                        <option></option>
                        <?php echo $options; ?>
                    </select>
                    <?php $input_select = ob_get_clean();

                    ob_start(); ?>
                    <li class="answer">
                        <span>
                            <b><?php echo self::$q_counter; ?></b>
                        </span> 
                        Answer: <span class="b-r"><?php echo $correct_answer; ?></span>
                        <div class="sl-item explanation">
                            <div class="sl-control"> 
                                <a class="explanation-click" title="Explain" data-toggle="collapse" data-target="#col-<?php echo self::$q_counter; ?>" href="javascript:void(0)"> 
                                    <span class="icon-explain"></span> Explain 
                                </a>
                                <?php if($this->is_loc){ ?>
                                <a class="locate-explain" data-q="<?php echo self::$q_counter; ?>" title="Locate" href="javascript:void(0)"> 
                                    <span class="icon-locale"></span> Locate 
                                </a>    
                                <?php } ?> 
                                <?php echo $question_listenFromHere_html; ?>
                            
                                <!--begin::report-->
                                <?php if($this->is_report){ ?>
                                <a 
                                    data-q_id="<?php echo $question_id; ?>" 
                                    data-q_type="select" 
                                    data-s_id="<?php echo $section_id; ?>" 
                                    data-q_item="<?php echo self::$q_counter; ?>" 
                                    class="locate-explain hide-mobile use-ajax"
                                    data-type="question-report"
                                >
                                    <i class="fa fa-exclamation-triangle"></i>
                                    Report
                                </a>
                                <?php } ?>
                                <!--end::report-->

                                <?php 
                                    self::$question_qt[] = (object) [
                                        "_id"           => $question_id,
                                        "counter"       => self::$q_counter,
                                        "type"          => $input_type,
                                        "section_id"    => $section_id
                                    ];
                                ?>
                                
                            </div>
                            <div id="col-<?php echo self::$q_counter; ?>" class="collapse">
                                <div align="left" dir="ltr" style="margin-left:-7px">
                                    <?php 
                                        $explanation = (object) $explanation;
                                        if(isset($explanation->html) && $explanation->html !== null){ 
                                            if(!empty($explanation->html)){
                                                echo $explanation->html;
                                            } else {
                                                echo "Correct answer is: <b>$correct_answer</b>"; 
                                            }
                                        } else { 
                                            echo "Correct answer is: <b>$correct_answer</b>"; 
                                        }
                                    ?>
                                </div>
                            </div>
                        </div>
                    </li>
                    <?php $exp_html = ob_get_clean();
                    $explanations_html .= $exp_html;

                    $html = $this->str_replace_first($expression,$input_select,$html);
                    
                }
            } else {
                $notice .= "It Looks like Question and Explanations are not available as the same amount";
                
            }

        }

        if($show_overall > 0){

            $group_listenFromHere_html = '';
            if( isset($groupListenSettings->status) && $groupListenSettings->status ) {
                if(isset($groupListenSettings->time)) {
                    ob_start(); ?>
                    <span class="listen-from-here proqyz-lfh" data-time="<?php echo $groupListenSettings->time; ?>">Listen from here</span>
                    <?php $group_listenFromHere_html = ob_get_clean();
                }
            }

            if ($q_total_questions > 1) {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        Questions <?php echo $before_q; ?>-<?php echo self::$q_counter; ?>
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                </div>
                <?php $headings = ob_get_clean();
            } else {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                </div>
                <?php $headings = ob_get_clean();
            }
        } else {
            $html = '';
        }

        

        return (object) ["html" => $html, "headings" => $headings, "explanations" => $explanations_html, "notice" => $notice ];
        

    }

    # checking - completed - working
    public function question_type_radio($pindex, $question = []){

        $question_html          = "";
        $question               = (object) $question;
        $question_id            = isset($question->_id)? $question->_id : '';
        $section_id             = isset($question->_postId)? $question->_postId : '';
        $section_id             = isset($question->_postId)? $question->_postId : '';
        $_questionSettings      = isset($question->_questionSettings)? (object) $question->_questionSettings : (object) [];
        $input_type             = isset($_questionSettings->inputType)? (string) $_questionSettings->inputType : null;
        $_answerSettings        = isset($question->_answerSettings)? (object) $question->_answerSettings : (object) [];
        $number_of_options      = isset($_answerSettings->numberOfOptions)? (int) $_answerSettings->numberOfOptions : 0;
        $answerType             = isset($_answerSettings->answerType)? (string) $_answerSettings->answerType : null;
        $answerTypes            = isset($_answerSettings->answerTypes)? (array) $_answerSettings->answerTypes : (array) [];
        $questions              = isset($question->questions)? (array) $question->questions : [];
        $explanations           = isset($question->explanations)? (array) $question->explanations : (array) [];
        $question_content       = isset($question->content)? (object) $question->content : (object) [];
        $html                   = isset($question_content->html)? (string) $question_content->html : "empty";
        $groupListenSettings    = isset($_questionSettings->audioTime)? (object) $_questionSettings->audioTime : (object) [ "status" => false, "time" => 0 ];
        
        $TYPE                   = "";

        $number_of_questions    = count($questions);
        $q_total_questions      =  (int) $number_of_questions;

        $before_q               = self::$q_counter + 1;
        $headings               = '';
        $modified_html          = "";
        $show_overall           = $q_total_questions;
        $notice                 = '';
        $explanations_html      = "";

        if( $number_of_questions == count($explanations)){
            foreach( $questions as $qkey => $qus ) {
                $qus            = (object) $qus;
                // $explanation    = isset($explanations[$qkey])? $explanations[$qkey] : (object) [ "html" => null ];
                $explanation    = isset($explanations[$qkey])? $explanations[$qkey] : (object) [ "html" => null, "istenFromHere" => (object) [
                    "status" => false,
                    "time"   => 0   
                ] ];

                $question_listenFromHere_html = '';
                if(isset($explanation->listenFromHere)){
                    $listenFromHere = (object) $explanation->listenFromHere;
                    if( isset($listenFromHere->status) && $listenFromHere->status ) {
                        if(isset($listenFromHere->time)) {
                            ob_start(); ?>
                            <a href="javascript:void(0)" class="proqyz-lfh" data-time="<?php echo $listenFromHere->time; ?>">
                                <span class="icon-listen"></span>
                                Listen from here
                            </a>
                            <?php $question_listenFromHere_html = ob_get_clean();
                        }
                    }  
                }          


                $question_html  = isset($qus->html)? $qus->html : '';
                $options        = isset($qus->options)? (array) $qus->options : [];

                if($number_of_questions > 0){
                    //self::$current_q_index++;
                    self::$q_counter++;
                    $number_of_questions--;

                    /**
                    * Resume logic
                     */
                    $fill_answer    = false;
                    $user_answer    = "";
                    $is_correct     = true;
                    $c_class        = '';
                    $qp_class       = '';
                    $correct_answer = '';

                    /**
                    * Result logic - Result logic
                    */
                    if( $this->is_result || $this->is_resume ) {
                        $response       = (object) $this->user_response;
                        $quiz_details   = isset($response->quiz)? (object) $response->quiz : null;
                        $user_answers   = isset($response->answers)? (array) $response->answers : null;
                
                        $current_question = isset($user_answers[self::$q_counter])? (object) $user_answers[self::$q_counter] : null;
                        if( $current_question ) {
                            $input_type     = isset($current_question->input_type)? $current_question->input_type : '';
                            $q_type         = isset($current_question->q_type)? $current_question->q_type : ''; 
                            $input_class    = isset($current_question->class)? $current_question->class : ''; 
                            $q_total        = isset($current_question->total)? (int) $current_question->total : 0;

                            if( $q_total == (int) $q_total_questions &&  $input_type == "radio" && $q_type == $TYPE && $input_class == "-checked" ) {
                                $fill_answer = true;
                                $user_answer = isset($current_question->answer)? $current_question->answer : '';
                            }
                        }
                            
                    }

                    ob_start();
                    if(count($options) > 0 ) {
                        foreach( $options as $okey => $option ) { 
                            $option     = (object) $option;
                            $oHtml      = isset($option->content)? $option->content : '';
                            $oCorrect   = isset($option->correct)? $option->correct : false;

                            $l_class    = ''; // default class
                            $u_class    = ''; // user class
                            $r_class    = ''; // user input class

                            if($oCorrect == "true"){
                                $correct_answer = $this->get_char($okey);
                                $l_class    = '-is-correct';
                            }

                            if( $fill_answer ){
                                # question is attempted

                                if( $oCorrect == "true" && $user_answer == $okey+1 ){
                                    $u_class    = '-attempt -correct -correct-radio';
                                    $r_class    = '-r-correct';
                                } 
                                    
                                if( $oCorrect != "true" && $user_answer == $okey+1){
                                    $is_correct = false;
                                    $u_class    = '-attempt -wrong -wrong-radio';
                                    $r_class    = '-r-wrong';
                                }

                            } else {
                                $u_class    = '-unattempt';
                            }

                            if( !$this->is_result ) {
                                $l_class    = ''; // default class
                                $u_class    = ''; // user class
                                $r_class    = ''; // user input class
                            }

                            ?>
                            <div class="test-panel__answer-item">
                                <div class="test-panel__answer-option <?php echo $l_class; ?> <?php echo $u_class; ?>">
                                    <?php echo $this->get_char($okey); ?>
                                </div>
                                <label for="radio-" class="iot-radio <?php echo $r_class; ?>">
                                    <input 
                                        data-c="<?php echo $oCorrect; ?>"
                                        type="radio" 
                                        class="question__input radio-iot iot-lr-question" 
                                        name="q-<?php echo self::$q_counter; ?>" 
                                        value="<?php echo $okey+1; ?>" 
                                        id="radio-<?php echo self::$q_counter; ?>-<?php echo $okey+1; ?>" 
                                        placeholder=""
                                        data-q_type="<?php echo $TYPE; ?>"
                                        data-input_type="radio"
                                        data-num="<?php echo self::$q_counter; ?>"
                                        data-id="q-<?php echo self::$q_counter; ?>"
                                        data-part="<?php echo $pindex+1; ?>"
                                        data-q_total="<?php echo $q_total_questions; ?>"
                                        <?php echo ($fill_answer && $user_answer == $okey+1)? 'checked' : ''; ?>
                                    />
                                    <?php echo $oHtml; ?>
                                </label>
                            </div>
                            <?php 
                        }
                    }
                    $radio_options = ob_get_clean();

                    // final result report for each question
                    if( $fill_answer){
                        self::$total_attempt++;
                        if($is_correct) {
                            
                            self::$total_correct++;
                            $c_class = '-attempt -correct -correct-radio';
                            $qp_class = '-qp-attempt -qp-correct';
                            self::$question_types[self::$q_counter] = (object) [
                                "q_type"        => $TYPE,
                                "q_input_type"  => "radio",
                                "q_p_index"     => $pindex+1,
                                "q_index"       => self::$q_counter,
                                "status"        => "correct"    
                            ];

                        } else {
                            
                            self::$total_wrong++;
                            $c_class = '-attempt -wrong -wrong-radio';
                            $qp_class = '-qp-attempt -qp-wrong';
                            self::$question_types[self::$q_counter] = (object) [
                                "q_type"        => $TYPE,
                                "q_input_type"  => "radio",
                                "q_p_index"     => $pindex+1,
                                "q_index"       => self::$q_counter,
                                "status"        => "wrong"    
                            ];
                        }
                    } else {
                        self::$total_unattempt++;
                        $c_class = '-unattempt';
                        $qp_class = '-qp-unattempt';
                        self::$question_types[self::$q_counter] = (object) [
                            "q_type"        => $TYPE,
                            "q_input_type"  => "radio",
                            "q_p_index"     => $pindex+1,
                            "q_index"       => self::$q_counter,
                            "status"        => "unattempt"    
                        ];
                    }

                    self::$question_qt[] = (object) [
                        "_id"           => $question_id,
                        "counter"       => self::$q_counter,
                        "type"          => $input_type,
                        "section_id"    => $section_id
                    ];
                                                

                    ob_start(); ?>
                        <div class="test-panel__question-sm-group">
                            <div class="test-panel__question-sm-title">
                                <span class="qp-item"><?php echo self::$q_counter; ?></span>
                                <?php echo $question_html; ?>
                            </div>
                            <div class="test-panel__answer">
                                <?php echo $radio_options; ?>
                            </div>
                            <?php if( $this->is_result ) { ?>
                            <div class="test-panel__answer">
                                <ul>
                                    <li class="answer"> 
                                        <span>
                                            <b><?php echo self::$q_counter; ?></b>
                                        </span>
                                        Answer: <span class="b-r"><?php echo $correct_answer; ?></span>
                                        <div class="sl-item explanation">
                                            <div class="sl-control"> 
                                                <a class="explanation-click" title="Explain" data-toggle="collapse" data-target="#col-<?php echo self::$q_counter; ?>" href="javascript:void(0)"> 
                                                    <span class="icon-explain"></span> Explain 
                                                </a> 
                                                <?php if($this->is_loc){ ?>
                                                <a class="locate-explain" data-q="<?php echo self::$q_counter; ?>" title="Locate" href="javascript:void(0)"> 
                                                    <span class="icon-locale"></span> Locate 
                                                </a>    
                                                <?php } ?>
                                                <?php echo $question_listenFromHere_html; ?>

                                                <!--begin::report-->
                                                <?php if($this->is_report){ ?>
                                                <a 
                                                    data-q_id="<?php echo $question_id; ?>" 
                                                    data-q_type="radio" 
                                                    data-s_id="<?php echo $section_id; ?>" 
                                                    data-q_item="<?php echo self::$q_counter; ?>" 
                                                    class="locate-explain hide-mobile use-ajax"
                                                    data-type="question-report"
                                                >
                                                    <i class="fa fa-exclamation-triangle"></i>
                                                    Report
                                                </a>
                                                <?php } ?>
                                                <!--end::report-->

                                                
                                            </div>
                                            <div id="col-<?php echo self::$q_counter; ?>" class="collapse">
                                                <div align="left" dir="ltr" style="margin-left:-7px">
                                                    <?php 
                                                        $explanation = (object) $explanation;
                                                        if(isset($explanation->html) && $explanation->html !== null){ 
                                                            if(!empty($explanation->html)){
                                                                echo $explanation->html;
                                                            } else {
                                                                echo "Correct answer is: <b>$correct_answer</b>"; 
                                                            }
                                                        } else { 
                                                            echo "Correct answer is: <b>$correct_answer</b>"; 
                                                        }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                </ul>    
                            </div>
                            <?php } ?>
                        </div>
                        <br />
                    <?php $modified_html .= ob_get_clean();
                }

            }
            
        } else {
            $notice .= "It Looks like Question and Explanations are not available as the same amount";
        }

        
        if($show_overall > 0){

            $group_listenFromHere_html = '';
            if( isset($groupListenSettings->status) && $groupListenSettings->status ) {
                if(isset($groupListenSettings->time)) {
                    ob_start(); ?>
                    <span class="listen-from-here proqyz-lfh" data-time="<?php echo $groupListenSettings->time; ?>">Listen from here</span>
                    <?php $group_listenFromHere_html = ob_get_clean();
                }
            }

            if ($q_total_questions > 1) {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        Questions <?php echo $before_q; ?>-<?php echo self::$q_counter; ?>
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                    <div class="test-panel__question-desc"><?php echo $html; ?></div>
                </div>
                <?php $headings = ob_get_clean();
            } else {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                    <div class="test-panel__question-desc"><?php echo $html; ?></div>
                </div>
                <?php $headings = ob_get_clean();
            }
        }

        return (object) ["html" => $modified_html, "headings" => $headings, "explanations" => $explanations_html, "notice" => $notice ];

    }

    # checking - 
    public function question_type_checkbox($pindex, $question = []){
        $question_html          = "";
        $question               = (object) $question;
        $question_id            = isset($question->_id)? $question->_id : '';
        $section_id             = isset($question->_postId)? $question->_postId : '';
        $_questionSettings      = isset($question->_questionSettings)? (object) $question->_questionSettings : (object) [];
        $combine                = isset($_questionSettings->combine)? $_questionSettings->combine : false;
        $input_type             = isset($_questionSettings->inputType)? (string) $_questionSettings->inputType : null;
        $explanations           = isset($question->explanations)? (array) $question->explanations : (array) [];
        $options                = isset($question->options)? (array) $question->options : [];
        $question_content       = isset($question->content)? (object) $question->content : (object) [];
        $html                   = isset($question_content->html)? (string) $question_content->html : "empty";
        $groupListenSettings    = isset($_questionSettings->audioTime)? (object) $_questionSettings->audioTime : (object) [ "status" => false, "time" => 0 ];
        $TYPE                   = "";
        $number_of_questions    = 0;




        if(count($options) > 0) {
            $correctObjects = array_filter($options, function ($object) {
                $option = (object) $object;
                return isset($option->correct) && ($option->correct == "true");
            });
            
            // Count the filtered array
            if($combine == "true" || $combine == "1"){
                $number_of_questions += count($correctObjects);
                
            } else {
                
                if(count($correctObjects) > 0){
                    $number_of_questions = 1;
                } else {
                    $number_of_questions = 0;
                }
            }
        }


        $q_total_questions      =  (int) $number_of_questions;

        $before_q               = self::$q_counter + 1;
        $last_q                 = self::$q_counter + $q_total_questions;

        $headings               = '';
        $modified_html          = "";
        $show_overall           = $q_total_questions;
        $notice                 = '';
        $explanations_html      = "";
        $answer_items           = "";
        $overall_q              = self::$q_counter + 1;
        if($combine == "true"){
            $overall_q = $before_q."-".$last_q;
        }

        $fill_answer            = false;
        $user_answers           = [];
        $q_total_correct        = 0;
        $q_total_wrong          = 0;
        $q_total_attempt        = 0;
        $q_total_unattempt      = 0;


        /**
         * resume | result
         */
        if( $this->is_resume || $this->is_result ) {
            $response       = (object) $this->user_response;
            $quiz_details   = isset($response->quiz)? (object) $response->quiz : null;
            $user_answers   = isset($response->answers)? (array) $response->answers : null;
            $current_question = isset($user_answers[$overall_q])? (object) $user_answers[$overall_q] : null;
            if( $current_question ) {

                $input_type     = isset($current_question->input_type)? $current_question->input_type : '';
                $q_type         = isset($current_question->q_type)? $current_question->q_type : ''; 
                $input_class    = isset($current_question->class)? $current_question->class : ''; 
                $q_total        = isset($current_question->total)? (int) $current_question->total : 0;
                $q_answers      = isset($current_question->answers)? (array) $current_question->answers : [];

                if( 
                    $q_total == (int) $q_total_questions && 
                    $input_type == "checkbox" && 
                    $q_type == $TYPE && 
                    $input_class == "-checked" &&
                    count($q_answers) > 0
                ) {
                    $fill_answer = true;
                    $user_answers = (array) $q_answers;
                }

            }
        }

        $is_overall_correct = true;
        $is_overall_attempt = false;
        $explanation_answer_boxes = "";
        $explanation_answers = [];


        if( $q_total_questions > 0 ) {
            $q_counter_exp = $before_q;
            $q_counter_exp_correct = 0;
            foreach($options as $okey => $option ) {
                $option         = (object) $option;
                $option_content = isset($option->content)? $option->content : 'Option '.($okey + 1);
                $correct        = isset($option->correct)? $option->correct : false;
                $explanation    = isset($explanations[$q_counter_exp_correct])? (object) $explanations[$q_counter_exp_correct] : (object) [ "html" => null, "istenFromHere" => (object) [
                    "status" => false,
                    "time"   => 0   
                ] ];
                
                $question_listenFromHere_html = '';
                if(isset($explanation->listenFromHere)){
                    $listenFromHere = (object) $explanation->listenFromHere;
                    if( isset($listenFromHere->status) && $listenFromHere->status ) {
                        if(isset($listenFromHere->time)) {
                            ob_start(); ?>
                            <a href="javascript:void(0)" class="proqyz-lfh" data-time="<?php echo $listenFromHere->time; ?>">
                                <span class="icon-listen"></span>
                                Listen from here
                            </a>
                            <?php $question_listenFromHere_html = ob_get_clean();
                        }
                    }  
                }      

                
                $d_class    = ""; # default class for correct
                $u_class    = "-unattempt"; # user class for label
                $ui_class   = "-unattempt"; # user base ui class

                $is_checked = false;

                if($correct == "true") {

                    $explanation_answers[] = $this->get_char($okey);
                    $d_class = "-is-correct";
                    if($combine == "true" || $combine == "1"){

                        // for each
                        ob_start(); ?>
                        <li class="answer">
                            <span>
                                <b><?php echo $q_counter_exp; ?></b>
                            </span> 
                            Answer: <span class="b-r"><?php echo $this->get_char($okey); ?></span>
                            <div class="sl-item explanation">
                                <div class="sl-control"> 
                                    <a class="explanation-click" title="Explain" data-toggle="collapse" data-target="#col-<?php echo $q_counter_exp; ?>" href="javascript:void(0)"> 
                                        <span class="icon-explain"></span> Explain 
                                    </a>
                                    <?php if($this->is_loc){ ?>
                                    <a class="locate-explain" data-q="<?php echo $q_counter_exp; ?>" title="Locate" href="javascript:void(0)"> 
                                        <span class="icon-locale"></span> Locate 
                                    </a>    
                                    <?php } ?> 
                                    <?php echo $question_listenFromHere_html; ?>                                    
                                    <!--begin::report-->
                                    <?php if($this->is_report){ ?>
                                    <a 
                                        data-q_id="<?php echo $question_id; ?>" 
                                        data-q_type="checkbox" 
                                        data-s_id="<?php echo $section_id; ?>" 
                                        data-q_item="<?php echo $q_counter_exp; ?>" 
                                        class="locate-explain hide-mobile use-ajax"
                                        data-type="question-report"
                                    >
                                        <i class="fa fa-exclamation-triangle"></i>
                                        Report
                                    </a>
                                    <?php } ?>
                                    <!--end::report-->

                                    <?php 
                                        self::$question_qt[] = (object) [
                                            "_id"           => $question_id,
                                            "counter"       => $q_counter_exp,
                                            "type"          => $input_type,
                                            "section_id"    => $section_id
                                        ];
                                    ?>

                                </div>
                                <div id="col-<?php echo $q_counter_exp; ?>" class="collapse">
                                    <div align="left" dir="ltr" style="margin-left:-7px">
                                        <?php 
                                            
                                            
                                            if(isset($explanation->html) && $explanation->html !== null){ 
                                                if(!empty($explanation->html)){
                                                    echo $explanation->html;
                                                } else {
                                                    echo "Correct answer is: <b>".$this->get_char($okey)."</b>"; 
                                                }
                                            } else { 
                                                echo "Correct answer is: <b>".$this->get_char($okey)."</b>";
                                            }
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <?php $explanation_answer_boxes .= ob_get_clean();
                        $q_counter_exp_correct++;
                        $q_counter_exp++;
                    }
                }

                if($fill_answer) {
                    if(count($user_answers) > 0 ) {
                        if($combine == "true" || $combine == "1"){
                            if(in_array($okey+1, $user_answers)){
                                $is_checked = true;
                                self::$total_attempt++;
                                $q_total_attempt++;
                                if( $correct == "true" ) {
                                    $u_class = "-correct -attempt -correct-checkbox";
                                    self::$total_correct++;
                                    $q_total_correct++;
                                    
                                } else {
                                    $u_class = "-wrong -attempt -wrong-checkbox";
                                    self::$total_wrong++;
                                    $q_total_wrong++;
                                }
                            } else {
                                $u_class = "-unattempt";
                                self::$total_unattempt++;
                                $q_total_unattempt++;
                            }
                        } else {
                            if(in_array($okey+1, $user_answers)){
                                $is_checked = true;
                                $is_overall_attempt = true;
                                if( $correct == "true" ) {
                                    $u_class = "-correct -attempt -correct-checkbox";
                                } else {
                                    $u_class = "-wrong -attempt -wrong-checkbox";
                                    $is_overall_correct = false;
                                }
                            } else {
                                $u_class = "-unattempt";
                            }
                        }
                    }
                }

                if( !$this->is_result ) {
                    $d_class    = ""; # default class for correct
                    $u_class    = ""; # user class for label
                    $ui_class   = "";
                }


                ob_start(); ?>
                <div class="test-panel__answer-item"> 
                    <span class="question-label__checkbox test-panel__answer-option <?php echo $d_class; ?> <?php echo $u_class; ?>">
                        <?php echo $this->get_char($okey); ?>
                    </span> 
                    <label class="iot-checkbox2" for="q-<?php echo $overall_q; ?>-<?php echo $this->get_char($okey); ?>"> 
                        <input 
                            type="checkbox" 
                            class="question__input checkbox-iot iot-lr-question" 
                            name="q-<?php echo $overall_q; ?>" 
                            value="<?php echo $okey+1; ?>" 
                            placeholder="" 
                            data-total-correct="<?php echo $q_total_questions; ?>"
                            data-q_type="<?php echo $TYPE; ?>"
                            data-input_type="checkbox"
                            data-num="<?php echo $overall_q; ?>" 
                            id="q-<?php echo $overall_q; ?>-<?php echo $this->get_char($okey); ?>" 
                            data-part="<?php echo $pindex+1; ?>"
                            data-q_total="<?php echo $q_total_questions; ?>"
                            <?php echo ($is_checked)? 'checked':''; ?>
                        /> 
                        <span class="checkmark"></span> 
                        <span class="cb-label"><?php echo $option_content; ?></span> 
                    </label>
                </div>
                <?php $answer_items .= ob_get_clean();
            }
        }

        if($fill_answer && count($user_answers) > 0){
            if($combine == "true" || $combine == "1"){
                self::$question_types[$overall_q] = (object) [
                    "q_type"        => $TYPE,
                    "q_input_type"  => "checkbox",
                    "q_p_index"     => $pindex+1,
                    "q_index"       => $overall_q,
                    "q_total"       => $q_total_questions,
                    "status"        => $q_total_correct > $q_total_wrong? "correct" : "wrong",
                    "correct"       => $q_total_correct,
                    "wrong"         => $q_total_wrong,
                    "attempt"       => count($user_answers),
                    "unattempt"     => $q_total_questions - count($user_answers)  
                ];


            } else {
                $oc_txt = "";
                if($is_overall_attempt){
                    self::$total_attempt++;
                    $q_total_attempt++;
                    if($is_overall_correct){
                        self::$total_correct++;
                        $q_total_correct++;
                        $oc_txt = "correct";
                    } else {
                        self::$total_wrong++;
                        $q_total_wrong++;
                        $oc_txt = "wrong";
                    }
                } else {
                    self::$total_unattempt++;
                    $q_total_unattempt++;
                }

                self::$question_types[$overall_q] = (object) [
                    "q_type"        => $TYPE,
                    "q_input_type"  => "checkbox",
                    "q_p_index"     => $pindex+1,
                    "q_index"       => $overall_q,
                    "q_total"       => $q_total_questions,
                    "status"        => $oc_txt,
                    "correct"       => $q_total_correct,
                    "wrong"         => $q_total_wrong,
                    "attempt"       => $is_overall_attempt? 1 : 0,
                    "unattempt"     => $is_overall_attempt? 0 : 1, 
                ];
            }
        } else {
            if($combine == "true" || $combine == "1"){
                self::$question_types[$overall_q] = (object) [
                    "q_type"        => $TYPE,
                    "q_input_type"  => "checkbox",
                    "q_p_index"     => $pindex+1,
                    "q_index"       => $overall_q,
                    "q_total"       => $q_total_questions,
                    "status"        => "unattempt",
                    "correct"       => 0,
                    "wrong"         => 0,
                    "attempt"       => 0,
                    "unattempt"     => $q_total_questions          
                ];
            } else {
                self::$question_types[$overall_q] = (object) [
                    "q_type"        => $TYPE,
                    "q_input_type"  => "checkbox",
                    "q_p_index"     => $pindex+1,
                    "q_index"       => $overall_q,
                    "q_total"       => $q_total_questions,
                    "status"        => "unattempt",
                    "correct"       => 0,
                    "wrong"         => 0,
                    "attempt"       => 0,
                    "unattempt"     => 1, 
                ];
            }
        }

        if($combine == "true" || $combine == "1"){
            self::$q_counter  = (self::$q_counter + (int) $q_total_questions);
        } else {
            self::$q_counter++;
        }

        # main content for display as html
        ob_start(); ?>
            <div class="test-panel__answer">
                <?php echo $answer_items; ?>
            </div>
        <?php $modified_html .= ob_get_clean();

        if($show_overall > 0){

            $group_listenFromHere_html = '';
            if( isset($groupListenSettings->status) && $groupListenSettings->status ) {
                if(isset($groupListenSettings->time)) {
                    ob_start(); ?>
                    <span class="listen-from-here proqyz-lfh" data-time="<?php echo $groupListenSettings->time; ?>">Listen from here</span>
                    <?php $group_listenFromHere_html = ob_get_clean();
                }
            }

            if ($q_total_questions > 1) {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        Questions <?php echo $before_q; ?>-<?php echo self::$q_counter; ?>
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                    <div class="test-panel__question-desc"><?php echo $html; ?></div>
                </div>
                <?php $headings = ob_get_clean();
            } else {
                ob_start(); ?>
                <div class="test-panel__question">
                    <h4 class="test-panel__question-title">
                        Questions <?php echo self::$q_counter; ?>
                        <?php echo $group_listenFromHere_html; ?>
                    </h4>
                    <div class="test-panel__question-desc"><?php echo $html; ?></div>
                </div>
                <?php $headings = ob_get_clean();
            }
        } else { }

        if($combine == "true" || $combine == "1"){
            ob_start(); ?>
            <ul>
                <?php echo $explanation_answer_boxes; ?>
            </ul>
            <?php $explanations_html = ob_get_clean();
        } else {
            $explanation    = isset($explanations[0])? (object) $explanations[0] : (object) [ "html" => null, "istenFromHere" => (object) [
                "status" => false,
                "time"   => 0   
            ] ];

            $question_listenFromHere_html = '';
            if(isset($explanation->listenFromHere)){
                $listenFromHere = (object) $explanation->listenFromHere;
                if( isset($listenFromHere->status) && $listenFromHere->status ) {
                    if(isset($listenFromHere->time)) {
                        ob_start(); ?>
                        <a href="javascript:void(0)" class="proqyz-lfh" data-time="<?php echo $listenFromHere->time; ?>">
                            <span class="icon-listen"></span>
                            Listen from here
                        </a>
                        <?php $question_listenFromHere_html = ob_get_clean();
                    }
                }  
            }         
    
            ob_start(); ?>
            <ul>
                <li class="answer">
                    <span>
                        <b><?php echo $before_q; ?></b>
                    </span> 
                    Answer: <span class="b-r"><?php echo implode(" <b style='color:black;'>|</b> ", $explanation_answers); ?></span>
                    <div class="sl-item explanation">
                        <div class="sl-control"> 
                            <a class="explanation-click" title="Explain" data-toggle="collapse" data-target="#col-<?php echo $before_q; ?>" href="javascript:void(0)"> 
                                <span class="icon-explain"></span> Explain 
                            </a>
                            <?php if($this->is_loc){ ?>
                            <a class="locate-explain" data-q="<?php echo $before_q; ?>" title="Locate" href="javascript:void(0)"> 
                                <span class="icon-locale"></span> Locate 
                            </a>    
                            <?php } ?> 
                            <?php echo $question_listenFromHere_html; ?>

                            <!--begin::report-->
                            <?php if($this->is_report){ ?>
                            <a 
                                data-q_id="<?php echo $question_id; ?>" 
                                data-q_type="radio" 
                                data-s_id="<?php echo $section_id; ?>" 
                                data-q_item="<?php echo $before_q; ?>" 
                                class="locate-explain hide-mobile use-ajax"
                                data-type="question-report"
                            >
                                <i class="fa fa-exclamation-triangle"></i>
                                Report
                            </a>
                            <?php } ?>
                            <!--end::report-->

                            <?php 
                                self::$question_qt[] = (object) [
                                    "_id"           => $question_id,
                                    "counter"       => $before_q,
                                    "type"          => $input_type,
                                    "section_id"    => $section_id
                                ];
                            ?>


                        </div>
                        <div id="col-<?php echo $before_q; ?>" class="collapse">
                            <div align="left" dir="ltr" style="margin-left:-7px">
                                <?php 
                                    
                                            
                                    if(isset($explanation->html) && $explanation->html !== null){ 
                                        if(!empty($explanation->html)){
                                            echo $explanation->html;
                                        } else {
                                            echo "Correct answer is: <b>".implode(" <b style='color:red;'>|</b> ", $explanation_answers)."</b>"; 
                                        }
                                    } else { 
                                        echo "Correct answer is: <b>".implode(" <b style='color:red;'>|</b> ", $explanation_answers)."</b>";
                                    }
                                ?>
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
            <?php $explanations_html = ob_get_clean();
        }



        return (object) ["html" => $modified_html, "headings" => $headings, "explanations" => $explanations_html, "notice" => $notice ];    

        
    }




    public function get_total_questions(){
        return self::$q_counter;
    }

    public function set_user_data( $user_data = [], $resume = false, $result = false ) {
        $this->user_response = (object) $user_data;
        $this->is_resume = $resume;
        $this->is_result = $result;
    }

    public function get_report(){
        return (object) [
            "types"         => (array) self::$question_types,
            "total"         => self::$q_counter,
            "correct"       => self::$total_correct,
            "wrong"         => self::$total_wrong,
            "attempt"       => self::$total_attempt,
            "unattempt"     => self::$total_unattempt
        ];
    }

    public static function get_report_questions_modal() {
        $user_id            = get_current_user_id();
        // current user email
        $user_data          = get_userdata($user_id);
        $user_email = '';
        $display_name = '';
        if ($user_data) {
            $user_email = $user_data->user_email; // User email
            $display_name = $user_data->display_name; // Display name

        }

        ob_start(); ?>
        <div id="report-question" class="modal ui-front fade modal-rpmistake" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static" style="display: none;background:#00000085;">
            <div class="modal-dialog js-drupal-dialog modal-auto" role="document" id="drupal-modal--dialog">
                <div class="ui-dialog" id="drupal-modal--content" style="max-height: 100%;">
                    <div class="modal-header ui-dialog-titlebar" id="drupal-modal--header" style="display: none;">
                        
                        <h4 class="modal-title ui-dialog-title">Report Mistakes</h4>
                    </div>
                    <div class="modal-body ui-dialog-content" id="drupal-modal--body">
                        <div id="modal-report-mistake">
                        <form id="report-mistake">
                            <div class="modal-rpmistake__contents">
                                <div class="modal-rpmistake__icon"></div>
                                <h2 class="modal-rpmistake__title">
                                    Found a mistake? Let us know!
                                </h2>
                                <div class="modal-rpmistake__desc">Please describe the mistake as detailed as possible along with your expected correction, leave your email so that we can contact you when needed. Thank you!</div>
                                <div class="modal-rpmistake__body">
                                    <div class="modal-rpmistake__question">
                                    What question is wrong?
                                    <select name="question" data-q_selector="question" class="selectpicker questions iot-select -rounded" required="required" tabindex="-98">
                                        <?php if(count(self::$question_qt) > 0) {
                                            foreach( self::$question_qt as $question) {
                                                ?>
                                                <option data-id="<?php echo $question->_id; ?>" data-sid="<?php echo $question->section_id; ?>" value="<?php echo $question->counter; ?>">
                                                    <?php echo $question->counter; ?> Question
                                                </option>
                                                <?php
                                            }
                                        } ?>
                                            
                                        <option value="other">Other</option>
                                    </select>
                                    </div>
                                    <div class="modal-rpmistake__describe">
                                    <label class="modal-rpmistake__describe-label" for="report-message">Please describe exactly what is wrong
                                    <span class="modal-rpmistake__asterisk">*</span>:</label>
                                    <textarea id="report-message" class="area-wrong form-control modal-rpmistake__mess" rows="5" name="describe-area" cols="10" required=""></textarea>
                                    <div class="error-message report-message"></div>
                                    <div class="modal-rpmistake__row">
                                        <div class="modal-rpmistake__col">
                                            <input readonly type="text" class="yourname form-control modal-rpmistake__input" name="userName" id="user-name" placeholder="User name" value="<?php echo $display_name; ?>" />
                                        </div>
                                        <div class="modal-rpmistake__col">
                                            <input readonly type="email" class="email form-control modal-rpmistake__input" name="userEmail" id="user-email" value="<?php echo $user_email; ?>" placeholder="Email (*)" required="">
                                            <div class="error-message report-email"></div>
                                        </div>
                                    </div>
                                    <div class="modal-rpmistake__footer">
                                        <button type="button" class="modal-rpmistake__btn iot-grbt -white" data-dismiss="modal">Cancel</button>
                                        <button type="submit" class="procced-submit-report modal-rpmistake__btn iot-grbt -main-color">
                                            Submit 
                                        </button>
                                    </div>
                                    
                                    </div>
                                </div>
                            </div>
                        </form>
                        </div>
                    </div>
                    <div class="modal-footer ui-dialog-buttonpane" id="drupal-modal--footer" style="display: none;"></div>
                </div>
                
            </div>
        </div>
        <div class="modal fade" id="modal-report" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" style="display: none;background:#00000070;z-index:9999;">
            <div class="modal-dialog modal-auto modal-profile js-drupal-dialog">
                <div class="">
                    <i class="ion-android-close close-modal" data-dismiss="modal" aria-label="Close"></i>
                    <div class="login-box report__feedback">
                        
                    </div>

                </div>
            </div>
        </div>
        <?php return ob_get_clean();
    }


}