Skip to content

Commit

Permalink
Resolved : The "Show correct answer inline" option is not working if …
Browse files Browse the repository at this point in the history
…two quizzes are on the
  • Loading branch information
krunalexpresstech committed Oct 6, 2023
1 parent 555914c commit 6d9675a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
14 changes: 8 additions & 6 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ function qmnInit() {
let $this = jQuery(this);
let value = $this.val();
let question_id = $this.attr('name').replace(/question/i, '');
let data = qsm_question_quick_result_js(question_id, value, '', qmn_quiz_data[key].enable_quick_correct_answer_info);
let data = qsm_question_quick_result_js(question_id, value, '', qmn_quiz_data[key].enable_quick_correct_answer_info,key);
if (data.success == 'correct') {
$this.parent().addClass("qmn_correct_answer");
} else if (data.success == 'incorrect') {
Expand Down Expand Up @@ -1612,7 +1612,7 @@ jQuery(function () {
function qsm_show_inline_result(quizID, question_id, value, $this, answer_type, $i_this, index = null) {
jQuery('.qsm-spinner-loader').remove();
addSpinnerLoader($this,$i_this);
let data = qsm_question_quick_result_js(question_id, value, answer_type, qmn_quiz_data[quizID].enable_quick_correct_answer_info);
let data = qsm_question_quick_result_js(question_id, value, answer_type, qmn_quiz_data[quizID].enable_quick_correct_answer_info,quizID);
$this.find('.quick-question-res-p').remove();
$this.find('.qsm-inline-correct-info').remove();
$this.find('.qmn_radio_answers').children().removeClass('data-correct-answer');
Expand Down Expand Up @@ -1826,7 +1826,7 @@ function checkMaxLength(obj){
let submit_status = true;
function qsm_submit_quiz_if_answer_wrong(question_id, value, $this, $quizForm, answer_type = '') {
let quiz_id = $quizForm.closest('.qmn_quiz_container').find('.qmn_quiz_id').val();
let data = qsm_question_quick_result_js(question_id, value, answer_type, qmn_quiz_data[quiz_id].enable_quick_correct_answer_info);
let data = qsm_question_quick_result_js(question_id, value, answer_type, qmn_quiz_data[quiz_id].enable_quick_correct_answer_info,quiz_id);
QSM.changes(data, question_id.replace(/\D/g, ""), quiz_id);
if (data.success == 'incorrect' && submit_status) {
$quizForm.closest('.qmn_quiz_container').find('[class*="Required"]').removeClass();
Expand All @@ -1837,9 +1837,11 @@ function qsm_submit_quiz_if_answer_wrong(question_id, value, $this, $quizForm, a
}
}

function qsm_question_quick_result_js(question_id, answer, answer_type = '', show_correct_info = '') {
if (typeof encryptedData !== 'undefined') {
let decryptedBytes = CryptoJS.AES.decrypt(encryptedData, encryptionKey);
function qsm_question_quick_result_js(question_id, answer, answer_type = '', show_correct_info = '',quiz_id='') {

if (typeof encryptedData[quiz_id] !== 'undefined') {

let decryptedBytes = CryptoJS.AES.decrypt(encryptedData[quiz_id], encryptionKey[quiz_id]);
let decryptedData = decryptedBytes.toString(CryptoJS.enc.Utf8);
let decrypt = JSON.parse(decryptedData);
question_id = typeof question_id !== 'undefined' ? parseInt(question_id) : 0;
Expand Down
27 changes: 23 additions & 4 deletions php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,30 @@ public function display_shortcode( $atts ) {
$encryption[ $question['question_id'] ]['correct_info_text'] = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $encryption[ $question['question_id'] ]['correct_info_text'], "correctanswerinfo-{$question['question_id']}" );
}
if ( ( isset($qmn_json_data['end_quiz_if_wrong']) && 0 < $qmn_json_data['end_quiz_if_wrong'] ) || ( ! empty( $qmn_json_data['enable_quick_result_mc'] ) && 1 == $qmn_json_data['enable_quick_result_mc'] ) ) {
$quiz_id = $qmn_json_data['quiz_id'];
$qsm_inline_encrypt_js = '
var encryptionKey = "'.hash('sha256',time()).'";
var data = '.wp_json_encode($encryption).';
var jsonString = JSON.stringify(data);
var encryptedData = CryptoJS.AES.encrypt(jsonString, encryptionKey).toString();';
if (encryptionKey === undefined) {
var encryptionKey = {};
}
if (data === undefined) {
var data = {};
}
if (jsonString === undefined) {
var jsonString = {};
}
if (encryptedData === undefined) {
var encryptedData = {};
}
encryptionKey['.$quiz_id.'] = "'.hash('sha256',time().$quiz_id).'";
data['.$quiz_id.'] = '.wp_json_encode($encryption).';
jsonString['.$quiz_id.'] = JSON.stringify(data['.$quiz_id.']);
encryptedData['.$quiz_id.'] = CryptoJS.AES.encrypt(jsonString['.$quiz_id.'], encryptionKey['.$quiz_id.']).toString();';
wp_add_inline_script('qsm_encryption', $qsm_inline_encrypt_js, 'after');
}

Expand Down

0 comments on commit 6d9675a

Please sign in to comment.