From 6d9675ac06829730f43f3d405d229b5b00b2f765 Mon Sep 17 00:00:00 2001 From: dev-krunal Date: Fri, 6 Oct 2023 14:47:19 +0530 Subject: [PATCH] Resolved : The "Show correct answer inline" option is not working if two quizzes are on the --- js/qsm-quiz.js | 14 +++++++------ php/classes/class-qmn-quiz-manager.php | 27 ++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index c916ee201..591a54aee 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -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') { @@ -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'); @@ -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(); @@ -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; diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index c58186e46..8b389f1c8 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -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'); }