Skip to content

Commit

Permalink
Merge pull request #2357 from QuizandSurveyMaster/dev
Browse files Browse the repository at this point in the history
Release 8.1.16
  • Loading branch information
etvarun authored Sep 20, 2023
2 parents 31f8785 + 02b9c03 commit 7c69ea7
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 41 deletions.
15 changes: 11 additions & 4 deletions css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,19 @@ footer.qsm-popup__footer button.qsm-popup-secondary-button:hover {
color: red;
display: block;
}

.quiz_section .mlw-file-upload-error-msg.mlw-file-upload-success-msg {
color: green;
display: block;
}
.quiz_section .remove-uploaded-file {
color: red;
border: 1px solid red;
width: 31px;
padding: 5px 5px 0px 5px;
display: inline-block;
cursor: pointer;
margin-top: 5px;
}
.quiz_section .loading-uploaded-file {
width: 20px;
margin-bottom: -5px;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,8 @@ var import_button;
question_id: answer['question_id'],
answerType: answer['answerType'],
form_type: qsmQuestionSettings.form_type,
quiz_system: qsmQuestionSettings.quiz_system
quiz_system: qsmQuestionSettings.quiz_system,
question_type: questionType,
};
if (answer['answerType'] == 'image') {
ansTemp = {
Expand All @@ -2258,7 +2259,8 @@ var import_button;
question_id: answer['question_id'],
answerType: answer['answerType'],
form_type: qsmQuestionSettings.form_type,
quiz_system: qsmQuestionSettings.quiz_system
quiz_system: qsmQuestionSettings.quiz_system,
question_type: questionType
};
}
jQuery(document).trigger('qsm_new_answer_template', [ansTemp, answer, questionType]);
Expand Down
1 change: 1 addition & 0 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,7 @@ jQuery(function () {
$this.parent('.quiz_section').find('.mlw_file_upload_hidden_path').val(obj.file_path);
$this.parent('.quiz_section').find('.mlw_file_upload_media_id').val(obj.media_id);
$this.parent('.quiz_section').find('.mlw-file-upload-error-msg').hide();
$this.parent('.quiz_section').find('.mlw-file-upload-error-msg').addClass('mlw-file-upload-success-msg').text(obj.message);
$this.parent('.quiz_section').find('.mlw-file-upload-error-msg').show();
} else {
$this.parent('.quiz_section').find('.mlw-file-upload-error-msg').removeClass('mlw-file-upload-success-msg');
Expand Down
4 changes: 2 additions & 2 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Quiz And Survey Master
* Description: Easily and quickly add quizzes and surveys to your website.
* Version: 8.1.15
* Version: 8.1.16
* Author: ExpressTech
* Author URI: https://quizandsurveymaster.com/
* Plugin URI: https://expresstech.io/
Expand Down Expand Up @@ -43,7 +43,7 @@ class MLWQuizMasterNext {
* @var string
* @since 4.0.0
*/
public $version = '8.1.15';
public $version = '8.1.16';

/**
* QSM Alert Manager Object
Expand Down
8 changes: 0 additions & 8 deletions php/admin/options-page-questions-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ function qsm_options_questions_tab_content() {
</div>
<?php
}
$randomness = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'randomness_order' );
if ( 0 != $randomness ) {
?>
<div class="notice notice-warning">
<p><?php esc_html_e( 'This quiz has the "Are the questions random?" option enabled. The pages below will not be used while that option is enabled. To turn off, go to the "Options" tab and set that option to "No".', 'quiz-master-next' ); ?></p>
</div>
<?php
}

$question_ids = $mlwQuizMasterNext->pluginHelper->get_questions_ids( $quiz_id );
if ( ! empty( $question_ids ) ) {
Expand Down
83 changes: 68 additions & 15 deletions php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,33 @@ public function qsm_upload_image_fd_question() {
echo wp_json_encode( $json );
}
} else {
$json['type'] = 'error';
$json['message'] = __( 'Incorrect File Type uploaded. Please upload the allowed file type!', 'quiz-master-next' );
echo wp_json_encode( $json );
if ( ! empty ($file_upload_type) ) {
$filestype = explode(',', $file_upload_type);
foreach ( $filestype as $file ) {
if ( strpos($file, '/') !== false ) {
$filetypes = explode('/', $file);
if ( ! empty($filetypes[0]) && 'application' == $filetypes[0] ) {
$filetypes_allowed[] = 'pdf';
} else {
$filetypes_allowed[] = $filetypes[0];
}
}else {
$filetypes_allowed[] = $file;
}
}
if ( count($filetypes_allowed) > 1 ) {
$files_allowed = implode(',', $filetypes_allowed);
} else {
$files_allowed = $filetypes_allowed[0]; // Just take the single element
}
$json['type'] = 'error';
$json['message'] = __('File Upload Unsuccessful! (Please upload ', 'quiz-master-next') . $files_allowed . __(' file type)', 'quiz-master-next');
echo wp_json_encode( $json );
} else {
$json['type'] = 'error';
$json['message'] = __( 'File Upload Unsuccessful! (Please select file type)', 'quiz-master-next' );
echo wp_json_encode( $json );
}
}
exit;
}
Expand Down Expand Up @@ -914,7 +938,7 @@ public function display_quiz( $options, $quiz_data, $question_amount, $shortcode
// If deprecated pagination setting is not used, use new system...
$pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );

if ( 0 == $options->randomness_order && 0 == $options->question_from_total && 0 == $options->pagination && is_countable($pages) && 0 !== count( $pages ) ) {
if ( 0 == $options->question_from_total && 0 == $options->pagination && is_countable($pages) && 0 !== count( $pages ) ) {
$this->display_pages( $options, $quiz_data );
} else {
// ... else, use older system.
Expand Down Expand Up @@ -971,6 +995,23 @@ public function display_pages( $options, $quiz_data ) {
$contact_fields = QSM_Contact_Manager::load_fields();
$animation_effect = isset( $options->quiz_animation ) && '' !== $options->quiz_animation ? ' animated ' . $options->quiz_animation : '';
$enable_pagination_quiz = isset( $options->enable_pagination_quiz ) && 1 == $options->enable_pagination_quiz ? true : false;
if ( ( 1 == $options->randomness_order || 2 == $options->randomness_order ) && is_array( $pages ) ) {
$pages = QMNPluginHelper::qsm_shuffle_assoc( $pages );
$question_list_array = array();
foreach ( $pages as &$question_ids ) {
shuffle( $question_ids );
$question_list_array = array_merge($question_list_array, $question_ids);
}
$question_list_str = implode( ',', $question_list_array );
?>
<script>
const d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = "question_ids_<?php echo esc_attr( $options->quiz_id ); ?> = <?php echo esc_attr( $question_list_str ) ?>; "+expires+"; path=/";
</script>
<?php
}
if ( 1 < count( $pages ) && 1 !== intval( $options->disable_first_page ) && ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) ) {
$qmn_json_data['first_page'] = true;
$message_before = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ), "quiz_message_before-{$options->quiz_id}" );
Expand Down Expand Up @@ -1268,19 +1309,13 @@ public function display_questions( $qmn_quiz_options, $qmn_quiz_questions, $qmn_
$current_page_number = 1;
foreach ( $qmn_quiz_questions as $mlw_question ) {
if ( 0 != $pagination_option ) {
if ( 1 == $pagination_option ) {
if ( 1 == $pagination_option || 1 == $pages_count % $pagination_option || 1 == $pages_count ) {
?>
<div class="qsm-auto-page-row qsm-apc-<?php echo esc_attr( $current_page_number ); ?>" style="display: none;">
<div class="qsm-auto-page-row qsm-apc-<?php echo esc_attr( $current_page_number ); ?>" data-apid="<?php echo esc_attr($current_page_number); ?>" style="display: none;">
<?php
$current_page_number++;
} else {
if ( 1 == $pages_count % $pagination_option || 1 == $pages_count ) { // beginning of the row or first.
?>
<div class="qsm-auto-page-row qsm-apc-<?php echo esc_attr( $current_page_number ); ?>" style="display: none;">
<?php
$current_page_number++;
}
}
echo apply_filters( 'qsm_auto_page_begin_pagination', '', ( $current_page_number - 1 ), $qmn_quiz_options, $qmn_quiz_questions );
}
echo apply_filters( 'qsm_auto_page_begin_row', '', ( $current_page_number - 1 ), $qmn_quiz_options, $qmn_quiz_questions );
}
$category_class = '';
Expand Down Expand Up @@ -1438,6 +1473,19 @@ public function display_end_section( $qmn_quiz_options, $qmn_array_for_variables
* @return string The content for the results page section
*/
public function display_results( $options, $data ) {
$quiz_id = ! empty( $_REQUEST['qmn_quiz_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['qmn_quiz_id'] ) ) : 0 ;
if ( ! isset( $_REQUEST['qsm_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['qsm_nonce'] ) ), 'qsm_submit_quiz_' . intval( $quiz_id ) ) ) {
echo wp_json_encode(
array(
'display' => htmlspecialchars_decode( 'Nonce Validation failed!' ),
'redirect' => false,
'result_status' => array(
'save_response' => false,
),
)
);
exit;
}
$result = $this->submit_results( $options, $data );
$results_array = $result;
return $results_array['display'];
Expand Down Expand Up @@ -1861,7 +1909,6 @@ public function submit_results( $qmn_quiz_options, $qmn_array_for_variables ) {
* @return array The results of the user's score
*/
public static function check_answers( $options, $quiz_data ) {

global $mlwQuizMasterNext;
$new_questions = array();
// Load the pages and questions
Expand Down Expand Up @@ -2100,7 +2147,13 @@ public static function check_answers( $options, $quiz_data ) {
}
}
}
foreach ( $question_data as $questiontype ) {
if ( 11 == $questiontype['question_type'] ) {
$total_questions = $total_questions - 1;
}
}


// Calculate Total Percent Score And Average Points Only If Total Questions Doesn't Equal Zero To Avoid Division By Zero Error
if ( 0 !== $total_questions ) {
$total_score = round( ( ( $total_correct / ( $total_questions - count( $hidden_questions ) ) ) * 100 ), 2 );
Expand Down
5 changes: 2 additions & 3 deletions php/question-types/qsm-question-type-file-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function qmn_file_upload_display( $id, $question, $answers ) {
$new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
qsm_question_title_func( $question, '', $new_question_title, $id );
?> <div></div><input type="file" class="mlw_answer_file_upload <?php echo esc_attr( $mlw_require_class ); ?>"/>
<div style="display: none;" class="loading-uploaded-file"><img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( get_site_url() . '/wp-includes/images/spinner-2x.gif' ); ?>"></div>
<div style="display: none;" class="remove-uploaded-file"><span class="dashicons dashicons-trash"></span></div>
<img style="display: none;" class="loading-uploaded-file" alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( get_site_url() . '/wp-includes/images/spinner-2x.gif' ); ?>">
<span style="display: none;" class="dashicons dashicons-trash remove-uploaded-file"></span>
<span style="display: none;" class='mlw-file-upload-error-msg'></span>
<input class="mlw_file_upload_hidden_path" type="hidden" value="" />
<input class="mlw_file_upload_hidden_nonce" type="hidden" value="" />
Expand Down Expand Up @@ -52,7 +52,6 @@ function qmn_file_upload_review( $id, $question, $answers ) {
$return_array['user_text'] = ($file_url) ? '<a target="_blank" href="' . $file_url . '">' . __( 'Click here to view', 'quiz-master-next' ) . '</a>' : __( 'No file uploaded', 'quiz-master-next' );
$return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( ', ', $correct_text_array ) : '';
$return_array['correct'] = $current_question->get_answer_status( 'url' );
$return_array['points'] = $current_question->get_points();
$return_array['user_answer'] = $user_text_array;
$return_array['correct_answer'] = $correct_text_array;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function qmn_horizontal_multiple_choice_display( $id, $question, $answers ) {
$size_style .= ' height:'.$image_height.'px !important;';
}
?>
<img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<img class="qsm-multiple-choice-horizontal-img" alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<span class="qsm_image_caption">
<?php
$caption_text = trim( htmlspecialchars_decode( $answer[3], ENT_QUOTES ) );
Expand Down
2 changes: 1 addition & 1 deletion php/question-types/qsm-question-type-multiple-choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function qmn_multiple_choice_display( $id, $question, $answers ) {
$size_style .= ' height:'.$image_height.'px !important;';
}
?>
<img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<img class="qsm-multiple-choice-img" alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<span class="qsm_image_caption">
<?php
$caption_text = trim( htmlspecialchars_decode($answer[3], ENT_QUOTES ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function qmn_horizontal_multiple_response_display( $id, $question, $answers ) {
$size_style .= ' height:'.$image_height.'px !important;';
}
?>
<img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<img class="qsm-multiple-response-horizontal-img" alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<span class="qsm_image_caption">
<?php
$caption_text = trim( htmlspecialchars_decode( $answer[3], ENT_QUOTES ) );
Expand Down
2 changes: 1 addition & 1 deletion php/question-types/qsm-question-type-multiple-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function qmn_multiple_response_display( $id, $question, $answers ) {
$size_style .= ' height:'.$image_height.'px !important;';
}
?>
<img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<img class="qsm-multiple-response-img" alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<span class="qsm_image_caption">
<?php
$caption_text = trim( htmlspecialchars_decode( $answer[3], ENT_QUOTES ) );
Expand Down
2 changes: 1 addition & 1 deletion php/question-types/qsm-question-type-polar.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function qmn_polar_display( $id, $question, $answers ) {
}
$left_image = $answers[0][0];
?>
<img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $left_image, ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<img class="qsm-polar-img" alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $left_image, ENT_QUOTES ) ) ); ?>" style="<?php echo esc_attr( $size_style ); ?>" />
<span class="qsm_image_caption">
<?php
$caption_text = trim( htmlspecialchars_decode( $answers[0][3], ENT_QUOTES ) );
Expand Down
1 change: 0 additions & 1 deletion php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ function qsm_variable_total_attempted_questions( $content, $mlw_quiz_array ) {
$content = str_replace( '%AMOUNT_ATTEMPTED%', $total_attempted_questions, $content );
return $content;
}

/**
* Show poll result
*
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: quiz, survey, lead, test, score, exam, questionnaire, question,wordpress q
Requires at least: 4.9
Tested up to: 6.3
Requires PHP: 5.4
Stable tag: 8.1.15
Stable tag: 8.1.16
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -163,6 +163,11 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
18. Database

== Changelog ==
= 8.1.16 (September 20, 2023) =
* Feature: Added option to use random question and answer with manual pagination
* Bug: Fix quiz score calculation issue with file upload question types
* Enhancement: Improved nonce validation logic

= 8.1.15 (September 11, 2023) =
* Bug: Fixed issue causing numeric responses of 0 to display as "No Answer Provided" in emails
* Bug: Fixed issue with next button while using manual pagination
Expand Down

0 comments on commit 7c69ea7

Please sign in to comment.