From 3d202c334ac29f2f570af705bda8fd76464fe36e Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Thu, 4 Jan 2024 18:53:33 +0530 Subject: [PATCH 1/7] release 8.2.0 --- css/qsm-admin-question.css | 32 ++- css/qsm-admin-rtl.css | 4 +- css/qsm-admin.css | 15 +- js/qsm-admin.js | 182 +++++++++++++++--- js/qsm-quiz.js | 27 ++- mlw_quizmaster2.php | 4 +- php/admin/options-page-questions-tab.php | 92 +++++---- php/admin/options-page-style-tab.php | 4 +- php/classes/class-qmn-quiz-manager.php | 9 +- php/classes/class-qsm-contact-manager.php | 6 +- php/shortcodes.php | 2 +- php/template-variables.php | 7 +- .../qsm-tempvar-question-answers.php | 1 + readme.txt | 8 +- 14 files changed, 301 insertions(+), 92 deletions(-) diff --git a/css/qsm-admin-question.css b/css/qsm-admin-question.css index 57b7a0f71..76ba60d12 100644 --- a/css/qsm-admin-question.css +++ b/css/qsm-admin-question.css @@ -136,13 +136,14 @@ .page-header-buttons { text-align: right; } -.question, .question-bank-question { +.qsm-question-container, .question-bank-question { box-sizing: border-box; background: #ffffff; border: 1px solid #dfd4d4; border-radius: 3px; padding: 6px 5px; - margin: 10px 20px 0; + margin: 10px 20px 0 35px; + position: relative; } .question a { text-decoration: none; @@ -194,6 +195,16 @@ font-style: italic; margin: 3px 0; } +.qsm-admin-select-question-input { + position: absolute; + top: calc(50% - 3px); + left: -25px; + visibility: hidden; +} +.question:hover .qsm-admin-select-question-input, +.qsm-admin-select-question-input:checked { + visibility: visible; +} .question-content>div { margin: 0 10px; } @@ -472,7 +483,7 @@ a.import-button.button.disable_import::before { padding: 15px 10px; background-color: #fafafa; border: 1px solid #cbcbcb; - margin: 0 20px 0; + margin: 0 20px 0 35px; box-sizing: border-box; border-top: medium none; } @@ -620,6 +631,21 @@ a#qsm-category-add-toggle { .question_info_tag { float: right; } +.qsm-admin-bulk-actions{ + margin-top: 10px; + text-align: right; + display: none; +} +input.qsm-admin-select-page-question { + margin-left: 10px; + margin-right: 10px; + display: inline-block; +} +.qsm-admin-select-page-question-label{ + color: #a6abaf; + font-size: 16px; + display: none; +} @media (min-width: 783px) and (max-width: 1199px) { #poststuff #post-body.columns-2 #side-sortables { min-width: unset; diff --git a/css/qsm-admin-rtl.css b/css/qsm-admin-rtl.css index cbd205e26..9710e2c33 100644 --- a/css/qsm-admin-rtl.css +++ b/css/qsm-admin-rtl.css @@ -19,4 +19,6 @@ .overview-main-wrapper .overview-inner-wrap {margin-left: 2%;margin-right: 0;} div.qsm_icon_wrap{left:0;right:auto;} .text-right{text-align: left !important;} -.text-left{text-align: right !important;} \ No newline at end of file +.text-left{text-align: right !important;} +.wp-core-ui .button-danger { color: #DC3232; border-color: #DC3232; } +.wp-core-ui .button-danger:hover { color: #ca1010; border-color: #ca1010; } \ No newline at end of file diff --git a/css/qsm-admin.css b/css/qsm-admin.css index 54a9d5bfb..7f6c8d577 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -1332,6 +1332,9 @@ tr .qsm-opt-desc { .form-table td fieldset label { margin-right: 20px !important; } +.qsm-font-light { + font-weight: 300; +} .form-table .qsm-opt-tr { position: relative; } @@ -1950,7 +1953,9 @@ td.scheduled_time_start { .notice-error.notice-advance-timer { padding: 10px 15px; } - +.notice-error.notice-advance-timer { + padding: 10px 15px; +} .qsm-page-setting-top { display: flex; } @@ -1958,6 +1963,7 @@ td.scheduled_time_start { .qsm-page-setting-top .qsm-page-setting-left span { width: 120px; display: inline-block; + margin-bottom: 5px; color: #000; font-weight: 500; margin: 0 5px 5px 0; @@ -3259,3 +3265,10 @@ input#duplicate_questions { background-color: #fff; color: #2c3338; } +.wp-core-ui .button-danger { + color: #DC3232; + border-color: #DC3232; +} +.wp-core-ui .button-danger:hover { + color: #ca1010; border-color: #ca1010; +} \ No newline at end of file diff --git a/js/qsm-admin.js b/js/qsm-admin.js index e7b6bba3f..90774518d 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -1511,10 +1511,11 @@ var QSMContact; tinymce: { forced_root_block: '', toolbar1: 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,wp_more,fullscreen,wp_adv', - toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help' + toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help,wp_code' }, quicktags: true, }; + jQuery(document).trigger('qsm_tinyMCE_settings_after', [settings]); wp.editor.initialize('email-template-' + QSMAdminEmails.total, settings); } jQuery(document).trigger('qsm_after_add_email_block', [conditions, to, subject, content, replyTo, QSMAdminEmails.total]); @@ -2237,10 +2238,11 @@ var import_button; tinymce: { forced_root_block: '', toolbar1: 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,alignjustify,link,wp_more,fullscreen,wp_adv', - toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help' + toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help,wp_code' }, quicktags: true, }; + jQuery(document).trigger('qsm_tinyMCE_settings_after', [settings]); wp.editor.initialize(textarea_id, settings); var anser = QSMQuestion.prepareQuestionText(answer[0]); $(textarea_id).val(anser); @@ -2477,10 +2479,11 @@ var import_button; tinymce: { forced_root_block: '', toolbar1: 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,alignjustify,link,wp_more,fullscreen,wp_adv', - toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help' + toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help,wp_code' }, quicktags: true, }; + jQuery(document).trigger('qsm_tinyMCE_settings_after', [settings]); wp.editor.initialize('question-text', settings); wp.editor.initialize('correct_answer_info', settings); }, @@ -2676,34 +2679,160 @@ var import_button; $('#delete-question-button').attr('data-question-iid', $(this).data('question-iid')); }); // removes question from database - $('#delete-question-button').click(function (event) { - event.preventDefault(); - var question_id = $(this).data('question-iid'); - $.ajax({ - url: ajaxurl, - method: 'POST', - data: { - 'action': 'qsm_delete_question_from_database', - 'question_id': question_id, - 'nonce': qsmQuestionSettings.single_question_nonce - }, - success: function (response) { - // do nothing + $(document).on('click', '.qsm-delete-question-button-btn', function () { + let question_id = $(this).attr('data-question-iid'); + let checkedValues = ""; + if ("selected-questions" == question_id || "all-questions" == question_id) { + if ("all-questions" == question_id) { + checkedValues = $('.qsm-admin-select-question-input') + .map(function () { + return $(this).val(); + }) + .get(); + } else { + checkedValues = $('.qsm-admin-select-question-input:checked') + .map(function () { + return $(this).val(); + }) + .get(); } - }); - remove.parents('.question').remove(); - QSMQuestion.countTotal(); - $('.save-page-button').trigger('click'); + let question_ids = checkedValues.join(','); + if (question_ids == undefined || question_ids == null || question_ids == '') { + return; + } + $.ajax({ + url: ajaxurl, + method: 'POST', + data: { + 'action': 'qsm_bulk_delete_question_from_database', + 'question_id': question_ids, + 'nonce': qsmQuestionSettings.single_question_nonce + }, + success: function (response) { + if (response.success) { + checkedValues.forEach(function (questionId) { + $('.question[data-question-id="' + questionId + '"]').remove(); + }); + jQuery('.qsm-admin-select-page-question').prop('checked',false); + QSMQuestion.countTotal(); + $('.save-page-button').trigger('click'); + } else { + QSMAdmin.displayAlert(response.data, 'error'); + } + jQuery('.qsm-admin-bulk-actions').fadeOut(); + } + }); + } else { + $.ajax({ + url: ajaxurl, + method: 'POST', + data: { + 'action': 'qsm_delete_question_from_database', + 'question_id': question_id, + 'nonce': qsmQuestionSettings.single_question_nonce + }, + success: function (response) { + if (response.success) { + remove.parents('.question').remove(); + QSMQuestion.countTotal(); + $('.save-page-button').trigger('click'); + } else { + QSMAdmin.displayAlert(response.data, 'error'); + } + } + }); + } MicroModal.close('modal-7'); }); + // delete bulk question from database + $(document).on('click', '#qsm-bulk-delete-question', function (event) { + event.preventDefault(); + MicroModal.show('modal-7'); + $('#unlink-question-button').attr('data-question-iid', 'selected-questions'); + $('#delete-question-button').attr('data-question-iid', 'selected-questions'); + }); + // remove bulk question from quiz + $(document).on('click', '#qsm-bulk-delete-all-question', function (event) { + event.preventDefault(); + MicroModal.show('modal-7'); + $('#unlink-question-button').attr('data-question-iid', 'all-questions'); + $('#delete-question-button').attr('data-question-iid', 'all-questions'); + }); + + $(document).on('click', '.qsm-admin-select-page-question', function () { + let isChecked = $(this).prop('checked'); + let checkboxesToToggle = $(this).closest('.page').find('.qsm-admin-select-question-input'); + checkboxesToToggle.prop('checked', isChecked); + if (!isChecked) { + $('.qsm-admin-select-page-question').prop('checked', false); + } else { + let allCheckboxesChecked = checkboxesToToggle.length === checkboxesToToggle.filter(':checked').length; + $('.qsm-admin-select-page-question').prop('checked', allCheckboxesChecked); + } + let count = jQuery('.qsm-admin-select-question-input:checked').length; + jQuery('.qsm-selected-question-count').html(count); + if (count) { + jQuery('.qsm-admin-bulk-actions').fadeIn(); + } else { + jQuery('.qsm-admin-bulk-actions').fadeOut(); + } + }); + + $(document).on('click', '.qsm-admin-select-question-input', function () { + if (!$(this).prop('checked')) { + $(this).closest('.page').find('.qsm-admin-select-page-question').prop('checked', false); + } else { + let allCheckboxesChecked = $(this).closest('.page').find('.qsm-admin-select-question-input:checked').length === $(this).closest('.page').find('.qsm-admin-select-question-input').length; + $(this).closest('.page').find('.qsm-admin-select-page-question').prop('checked', allCheckboxesChecked); + } + if ( $(this).closest('.page').find('.qsm-admin-select-question-input:checked').length ) { + $(this).closest('.page').find('.qsm-admin-select-page-question-label').fadeIn(); + } else { + $(this).closest('.page').find('.qsm-admin-select-page-question-label').fadeOut(); + } + let count = jQuery('.qsm-admin-select-question-input:checked').length; + jQuery('.qsm-selected-question-count').html(count); + if (count) { + jQuery('.qsm-admin-bulk-actions').fadeIn(); + } else { + jQuery('.qsm-admin-bulk-actions').fadeOut(); + } + }); // unlink question from a particular quiz. - $('#unlink-question-button').click(function (event) { + $(document).on('click', '.qsm-unlink-question-button-btn', function (event) { event.preventDefault(); - var question_id = $(this).data('question-iid'); - remove.parents('.question').remove(); - QSMQuestion.countTotal(); - $('.save-page-button').trigger('click'); + let question_id = $(this).attr('data-question-iid'); + let checkedValues = ""; + if ("selected-questions" == question_id || "all-questions" == question_id) { + if ("all-questions" == question_id) { + checkedValues = $('.qsm-admin-select-question-input') + .map(function () { + return $(this).val(); + }) + .get(); + } else { + checkedValues = $('.qsm-admin-select-question-input:checked') + .map(function () { + return $(this).val(); + }) + .get(); + } + let question_ids = checkedValues.join(','); + if (undefined != question_ids && null != question_ids && '' != question_ids) { + checkedValues.forEach(function (questionId) { + $('.question[data-question-id="' + questionId + '"]').remove(); + }); + QSMQuestion.countTotal(); + $('.save-page-button').trigger('click'); + jQuery('.qsm-admin-bulk-actions').fadeOut(); + jQuery('.qsm-admin-select-page-question').prop('checked',false); + } + } else { + remove.parents('.question').remove(); + QSMQuestion.countTotal(); + $('.save-page-button').trigger('click'); + } MicroModal.close('modal-7'); }); @@ -3348,10 +3477,11 @@ var import_button; tinymce: { forced_root_block: '', toolbar1: 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,wp_more,fullscreen,wp_adv', - toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help' + toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help,wp_code' }, quicktags: true, }; + jQuery(document).trigger('qsm_tinyMCE_settings_after', [settings]); wp.editor.initialize('results-page-' + QSMAdminResults.total, settings); jQuery(document).trigger('qsm_after_add_result_block', [conditions, page, redirect, QSMAdminResults.total]); }, diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 210b96dfd..f5d69ec40 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -755,8 +755,7 @@ function qmnValidation(element, quiz_form_id) { by_pass = false; } - if (localStorage.getItem('mlw_time_quiz' + quiz_id) === null || localStorage.getItem('mlw_time_quiz' + quiz_id) > 0.08 || by_pass === false) { - + if (localStorage.getItem('mlw_time_quiz' + quiz_id) === null || 0 == localStorage.getItem('mlw_time_quiz' + quiz_id) || localStorage.getItem('mlw_time_quiz' + quiz_id) > 0.08 || by_pass === false) { if (jQuery(this).attr('class').indexOf('mlwRequiredNumber') > -1 && this.value === "" && +this.value != NaN) { qmnDisplayError(error_messages.number_error_text, jQuery(this), quiz_form_id); show_result_validation = false; @@ -806,8 +805,10 @@ function qmnValidation(element, quiz_form_id) { } //Google recaptcha validation if (jQuery(this).attr('class').indexOf('g-recaptcha-response') > -1) { - if (grecaptcha.getResponse() == "") { - alert('ReCaptcha is missing'); + let recaptcha_id = jQuery(this).attr('id'); + let recaptcha_index = 'g-recaptcha-response' === recaptcha_id ? 0 : recaptcha_id.replace("g-recaptcha-response-", ""); + if (grecaptcha.getResponse(recaptcha_index) == "") { + alert(error_messages.recaptcha_error_text); show_result_validation = false; } } @@ -960,8 +961,10 @@ function qmnInit() { jQuery('.qmn-multiple-choice-input, .qsm_dropdown, .qsm-multiple-response-input').change(function () { let $this = jQuery(this); let value = $this.val(); + let quiz_form_id = $this.parents('.qsm-quiz-form').attr('id'); + let quiz_id = quiz_form_id.replace('quizForm', ''); 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,key); + let data = qsm_question_quick_result_js(question_id, value, '', qmn_quiz_data[quiz_id].enable_quick_correct_answer_info, quiz_id); if (data.success == 'correct') { $this.parent().addClass("qmn_correct_answer"); } else if (data.success == 'incorrect') { @@ -1327,7 +1330,20 @@ function qmnInitPagination(quiz_id) { jQuery(document).trigger('qsm_init_pagination_after', [quiz_id, qmn_quiz_data]); } +jQuery(document).on('qsm_next_button_click_after qsm_previous_button_click_after', function(event, quiz_id) { + let video_sections = jQuery(`.qsm-quiz-container-${quiz_id}.qmn_quiz_container`).find('video'); + let iframeVideos = jQuery(`.qsm-quiz-container-${quiz_id}.qmn_quiz_container`).find('iframe'); + iframeVideos.each(function() { + let src = this.src; + jQuery(this).attr('src', src); + }); + video_sections.each(function() { + if (!this.paused) { + this.pause(); + } + }); +}); function qmnSocialShare(network, mlw_qmn_social_text, mlw_qmn_title, facebook_id, share_url) { var sTop = window.screen.height / 2 - (218); var sLeft = window.screen.width / 2 - (313); @@ -1675,7 +1691,6 @@ jQuery(function () { jQuery('.pagetime-goto-nextpage').click(function (e) { e.preventDefault(); var quiz_id = jQuery(this).data('quiz_id'); - QSM.nextPage(quiz_id); var $container = jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container'); if(!$container.find('.qsm-submit-btn').is(':visible')) { QSM.nextPage(quiz_id); diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index 64fe0c7eb..b4130e1b5 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -2,7 +2,7 @@ /** * Plugin Name: Quiz And Survey Master * Description: Easily and quickly add quizzes and surveys to your website. - * Version: 8.2.0 + * Version: 8.2.1 * Author: ExpressTech * Author URI: https://quizandsurveymaster.com/ * Plugin URI: https://expresstech.io/ @@ -43,7 +43,7 @@ class MLWQuizMasterNext { * @var string * @since 4.0.0 */ - public $version = '8.2.0'; + public $version = '8.2.1'; /** * QSM Alert Manager Object diff --git a/php/admin/options-page-questions-tab.php b/php/admin/options-page-questions-tab.php index 2c84953b0..bc1587f3d 100644 --- a/php/admin/options-page-questions-tab.php +++ b/php/admin/options-page-questions-tab.php @@ -201,10 +201,14 @@ function qsm_options_questions_tab_content() {
+
+ + +
@@ -608,7 +612,7 @@ class="save-page-button button button-primary"> array( 'label' => __( 'Required?', 'quiz-master-next' ), 'type' => 'single_checkbox', - 'priority' => '2', + 'priority' => '3', 'options' => array( '0' => __( 'Yes', 'quiz-master-next' ), ), @@ -779,8 +783,8 @@ class="save-page-button button button-primary">
- - + +
@@ -1102,37 +1106,41 @@ function qsm_delete_question_question_bank() { */ function qsm_delete_question_from_database() { if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'delete_question_from_database' ) ) { - echo wp_json_encode( - array( - 'success' => false, - 'message' => __( - 'Nonce verification failed.', - 'quiz-master-next' - ), - ) - ); - wp_die(); + wp_send_json_error( __( 'Nonce verification failed.', 'quiz-master-next' ) ); } $question_id = isset( $_POST['question_id'] ) ? intval( $_POST['question_id'] ) : 0; if ( $question_id ) { - global $wpdb; - $wpdb->delete( $wpdb->prefix . 'mlw_questions', array( 'question_id' => $question_id ) ); - echo wp_json_encode( - array( - 'success' => true, - 'message' => __( - 'Question removed Successfully.', - 'quiz-master-next' - ), - ) - ); + global $wpdb, $mlwQuizMasterNext; + $results = $wpdb->delete( $wpdb->prefix . 'mlw_questions', array( 'question_id' => $question_id ) ); + if ( $results ) { + wp_send_json_success( __( 'Question removed Successfully.', 'quiz-master-next' ) ); + }else { + wp_send_json_error( __( 'Question delete failed!', 'quiz-master-next' ) ); + $mlwQuizMasterNext->log_manager->add( __('Error 0001 delete questions failed - question ID:', 'quiz-master-next') . $question_id, '
Error:' . $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); + } } - exit; } add_action( 'wp_ajax_qsm_delete_question_from_database', 'qsm_delete_question_from_database' ); -add_action( 'wp_ajax_save_new_category', 'qsm_save_new_category' ); +function qsm_bulk_delete_question_from_database() { + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'delete_question_from_database' ) ) { + wp_send_json_error( __( 'Nonce verification failed!', 'quiz-master-next' ) ); + } + $question_id = isset( $_POST['question_id'] ) ? sanitize_text_field( wp_unslash( $_POST['question_id'] ) ) : 0; + if ( $question_id ) { + global $wpdb, $mlwQuizMasterNext; + $results = $wpdb->query( "DELETE FROM {$wpdb->prefix}mlw_questions WHERE question_id IN ($question_id)" ); + if ( $results ) { + wp_send_json_success( __( 'Questions removed Successfully.', 'quiz-master-next' ) ); + }else { + wp_send_json_error( __( 'Question delete failed!', 'quiz-master-next' ) ); + $mlwQuizMasterNext->log_manager->add( __('Error 0001 delete questions failed - question IDs:', 'quiz-master-next') . $question_id, '
Error:' . $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' ); + } + } +} +add_action( 'wp_ajax_qsm_bulk_delete_question_from_database', 'qsm_bulk_delete_question_from_database' ); +add_action( 'wp_ajax_save_new_category', 'qsm_save_new_category' ); function qsm_save_new_category() { $category = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; $parent = isset( $_POST['parent'] ) ? intval( $_POST['parent'] ) : ''; @@ -1168,6 +1176,7 @@ function qsm_options_questions_tab_template() { +