$quiz_answer[$question_set][$i] = $_POST['question' . $i];
                        } else {
                            $quiz_answer[$question_set][$i] = stripslashes($_POST['question' . $i]);
                        }
                    }
                }
                $quiz_score = array();
                $quiz_status = 'pending';
                if ($_GET['course_page'] == 'finish') {
                    $quiz_score = gdlr_lms_calculating_score($quiz_options, $quiz_answer, $quiz_score);
                    $quiz_status = sizeof($quiz_score) == sizeof($quiz_options) ? 'complete' : 'submitted';
                    if ($quiz_status == 'complete' && (!empty($course_options['enable-badge']) && $course_options['enable-badge'] == 'enable')) {
                        gdlr_lms_add_badge(get_the_ID(), gdlr_lms_score_summary($quiz_score), $course_options['badge-percent'], $course_options['badge-title'], $course_options['badge-file']);
                    }
                    if ($quiz_status == 'complete' && (!empty($course_options['enable-certificate']) && $course_options['enable-certificate'] == 'enable')) {
                        gdlr_lms_add_certificate(get_the_ID(), $course_options['certificate-template'], gdlr_lms_score_summary($quiz_score), $course_options['certificate-percent']);
                    }
                }
                if ($current_row) {
                    $wpdb->update($wpdb->prefix . 'gdlrquiz', array('quiz_answer' => serialize($quiz_answer), 'quiz_score' => serialize($quiz_score), 'quiz_status' => $quiz_status), array('quiz_id' => $course_options['quiz'], 'student_id' => $current_user->ID, 'course_id' => get_the_ID()), array('%s', '%s', '%s'), array('%d', '%d'));
                } else {
                    $wpdb->insert($wpdb->prefix . 'gdlrquiz', array('quiz_id' => $course_options['quiz'], 'student_id' => $current_user->ID, 'course_id' => get_the_ID(), 'quiz_answer' => serialize($quiz_answer), 'quiz_score' => serialize($quiz_score), 'quiz_status' => $quiz_status), array('%d', '%d', '%s', '%s', '%s', '%s'));
                }
            }
        }
    }
}
if (isset($_GET['course_page']) && $_GET['course_page'] == 'finish') {
    exit;
}
get_header();
$quiz_answer = unserialize($current_row->quiz_answer);
$quiz_score = unserialize($current_row->quiz_score);
$quiz_score = empty($quiz_score) ? array() : $quiz_score;
$score_summary = gdlr_lms_score_part_summary($quiz_score);
$pnum = 0;
foreach ($quiz_options as $quiz_option) {
    echo '<tr>';
    echo '<td>' . $quiz_option['section-name'] . '</td>';
    echo '<td>';
    echo empty($score_summary[$pnum]) ? __('Pending', 'gdlr-lms') : $score_summary[$pnum]['score'] . '/' . $score_summary[$pnum]['from'];
    echo '</td>';
    echo '</tr>';
    $pnum++;
}
// summary
$score_summary = gdlr_lms_score_summary($quiz_score);
echo '<tr>';
echo '<td>' . __('Overall', 'gdlr-lms') . '</td>';
echo '<td>';
echo $score_summary['score'] . '/' . $score_summary['from'];
echo '</td>';
echo '</tr>';
?>
</table>

<!-- scoring part -->
<?php 
$pnum = 0;
foreach ($quiz_options as $quiz_option) {
    //display only large and small fill
    //if( $quiz_option['question-type'] == 'large' || $quiz_option['question-type'] == 'small' ){
                if ($_POST['action'] == 'scoring-status-part') {
                    $quiz_val = gdlr_lms_decode_preventslashes(get_post_meta($_GET['quiz_id'], 'gdlr-lms-content-settings', true));
                    $quiz_options = empty($quiz_val) ? array() : json_decode($quiz_val, true);
                    if (!empty($_POST)) {
                        $sql = 'SELECT id, quiz_score FROM ' . $wpdb->prefix . 'gdlrquiz ';
                        $sql .= 'WHERE quiz_id=' . $_GET['quiz_id'] . ' AND student_id=' . $_GET['student_id'] . ' AND course_id=' . $_GET['course_id'];
                        $current_row = $wpdb->get_row($sql);
                        $quiz_score = unserialize($current_row->quiz_score);
                        $quiz_score = empty($quiz_score) ? array() : $quiz_score;
                        $quiz_score[$_POST['pnum']] = array();
                        foreach ($_POST['score'] as $key => $value) {
                            $quiz_score[$_POST['pnum']][$key] = array('score' => $value, 'from' => $_POST['from'][$key]);
                        }
                        $quiz_status = sizeof($quiz_score) == sizeof($quiz_options) ? 'complete' : 'pending';
                        if ($quiz_status == 'complete') {
                            $course_val = gdlr_lms_decode_preventslashes(get_post_meta($_GET['course_id'], 'gdlr-lms-course-settings', true));
                            $course_settings = empty($course_val) ? array() : json_decode($course_val, true);
                            if (!empty($course_settings['enable-badge']) && $course_settings['enable-badge'] == 'enable') {
                                gdlr_lms_add_badge($_GET['course_id'], gdlr_lms_score_summary($quiz_score), $course_settings['badge-percent'], $course_settings['badge-title'], $course_settings['badge-file'], $_GET['student_id']);
                            }
                            if (!empty($course_settings['enable-certificate']) && $course_settings['enable-certificate'] == 'enable') {
                                gdlr_lms_add_certificate($_GET['course_id'], $course_settings['certificate-template'], gdlr_lms_score_summary($quiz_score), $course_settings['certificate-percent'], $_GET['student_id']);
                            }
                        }
                        $wpdb->update($wpdb->prefix . 'gdlrquiz', array('quiz_score' => serialize($quiz_score), 'quiz_status' => $quiz_status), array('id' => $current_row->id), array('%s', '%s'), array('%d'));
                    }
                }
            }
        }
    }
}