Quiz And Survey Master (Formerly Quiz Master Next) - Version 6.3.1

Version Description

(May 19, 2019) = * Closed Bug: Duplicate post issue (Issue #758) * Closed Enhancement: Option to turn off autofill (WP Issue) * Added Feature: Preview quiz within the quiz edit page. * Added Feature: Auto save quiz and questions * Closed Enhancement: Disable autofill for contact fields (Issue #718) * Closed Enhancement: Added %POLL_RESULTS_X% tag for results page to show poll results (Issue #458) * Closed Bug: Facebook Share not working properly (WP Issue)

Download this release

Release Info

Developer quizsurvey
Plugin Icon 128x128 Quiz And Survey Master (Formerly Quiz Master Next)
Version 6.3.1
Comparing to
See all releases

Code changes from version 6.3.0 to 6.3.1

js/qsm-admin-contact.js CHANGED
@@ -6,9 +6,11 @@ var QSMContact;
6
  (function ($) {
7
  QSMContact = {
8
  load : function() {
9
- $.each( qsmContactObject.contactForm, function( i, val ) {
10
- QSMContact.addField( val );
11
- });
 
 
12
  },
13
  addField : function( fieldArray ) {
14
  var contactField = $( '<div class="contact-form-field new">' +
6
  (function ($) {
7
  QSMContact = {
8
  load : function() {
9
+ if(qsmContactObject.contactForm.length > 0){
10
+ $.each( qsmContactObject.contactForm, function( i, val ) {
11
+ QSMContact.addField( val );
12
+ });
13
+ }
14
  },
15
  addField : function( fieldArray ) {
16
  var contactField = $( '<div class="contact-form-field new">' +
js/qsm-admin-question.js CHANGED
@@ -243,6 +243,7 @@ var QSMQuestion;
243
  var comments = $( "#comments" ).val();
244
  var required = $( "#required" ).val();
245
  var category = $( ".category-radio:checked" ).val();
 
246
  if ( 'new_category' == category ) {
247
  category = $( '#new_category' ).val();
248
  }
@@ -280,6 +281,7 @@ var QSMQuestion;
280
  required: required,
281
  answers: answers,
282
  answer_editor: answerType,
 
283
  },
284
  {
285
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
@@ -338,6 +340,11 @@ var QSMQuestion;
338
  if( answerEditor === null || typeof answerEditor === "undefined" ){
339
  answerEditor = 'text';
340
  }
 
 
 
 
 
341
  var al = 0;
342
  _.each( answers, function( answer ) {
343
  answer.push(al + 1);
@@ -351,8 +358,10 @@ var QSMQuestion;
351
  $( "#question_type" ).val( question.get( 'type' ) );
352
  $( "#comments" ).val( question.get( 'comments' ) );
353
  $( "#required" ).val( question.get( 'required' ) );
 
354
  $( "#change-answer-editor" ).val( answerEditor );
355
  $( ".category-radio" ).removeAttr( 'checked' );
 
356
  if ( 0 !== question.get( 'category' ).length ) {
357
  $( ".category-radio" ).val( [question.get( 'category' )] );
358
  }
@@ -412,6 +421,7 @@ var QSMQuestion;
412
  event.preventDefault();
413
  $( this ).parents( '.question' ).remove();
414
  QSMQuestion.countTotal();
 
415
  });
416
  $( '.questions' ).on( 'click', '.delete-page-button', function( event ) {
417
  event.preventDefault();
@@ -424,6 +434,7 @@ var QSMQuestion;
424
  $( '#save-popup-button' ).on( 'click', function( event ) {
425
  event.preventDefault();
426
  QSMQuestion.saveQuestion( $( this ).parent().siblings( 'main' ).children( '#edit_question_id' ).val() );
 
427
  });
428
  $( '#new-answer-button' ).on( 'click', function( event ) {
429
  event.preventDefault();
243
  var comments = $( "#comments" ).val();
244
  var required = $( "#required" ).val();
245
  var category = $( ".category-radio:checked" ).val();
246
+ var autofill = $( "#hide_autofill" ).val();
247
  if ( 'new_category' == category ) {
248
  category = $( '#new_category' ).val();
249
  }
281
  required: required,
282
  answers: answers,
283
  answer_editor: answerType,
284
+ autofill: autofill
285
  },
286
  {
287
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
340
  if( answerEditor === null || typeof answerEditor === "undefined" ){
341
  answerEditor = 'text';
342
  }
343
+ //Check autofill setting
344
+ var disableAutofill = question.get( 'autofill' );
345
+ if( disableAutofill === null || typeof disableAutofill === "undefined" ){
346
+ disableAutofill = '0';
347
+ }
348
  var al = 0;
349
  _.each( answers, function( answer ) {
350
  answer.push(al + 1);
358
  $( "#question_type" ).val( question.get( 'type' ) );
359
  $( "#comments" ).val( question.get( 'comments' ) );
360
  $( "#required" ).val( question.get( 'required' ) );
361
+ $( "#hide_autofill" ).val( disableAutofill );
362
  $( "#change-answer-editor" ).val( answerEditor );
363
  $( ".category-radio" ).removeAttr( 'checked' );
364
+ $( "#edit-question-id" ).text('').text(questionID);
365
  if ( 0 !== question.get( 'category' ).length ) {
366
  $( ".category-radio" ).val( [question.get( 'category' )] );
367
  }
421
  event.preventDefault();
422
  $( this ).parents( '.question' ).remove();
423
  QSMQuestion.countTotal();
424
+ $('.save-page-button').trigger('click');
425
  });
426
  $( '.questions' ).on( 'click', '.delete-page-button', function( event ) {
427
  event.preventDefault();
434
  $( '#save-popup-button' ).on( 'click', function( event ) {
435
  event.preventDefault();
436
  QSMQuestion.saveQuestion( $( this ).parent().siblings( 'main' ).children( '#edit_question_id' ).val() );
437
+ $('.save-page-button').trigger('click');
438
  });
439
  $( '#new-answer-button' ).on( 'click', function( event ) {
440
  event.preventDefault();
js/qsm-quiz.js CHANGED
@@ -699,7 +699,7 @@ function qmnSocialShare( network, mlw_qmn_social_text, mlw_qmn_title, facebook_i
699
  if ( network == 'facebook' ) {
700
  url = "https://www.facebook.com/dialog/feed?" + "display=popup&" + "app_id="+facebook_id +
701
  "&" + "link=" + pageUrlEncoded + "&" + "name=" + encodeURIComponent(mlw_qmn_social_text) +
702
- "&" + "description= &" + "redirect_uri=http://www.mylocalwebstop.com/mlw_qmn_close.html";
703
  }
704
  if ( network == 'twitter' ) {
705
  url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(mlw_qmn_social_text);
699
  if ( network == 'facebook' ) {
700
  url = "https://www.facebook.com/dialog/feed?" + "display=popup&" + "app_id="+facebook_id +
701
  "&" + "link=" + pageUrlEncoded + "&" + "name=" + encodeURIComponent(mlw_qmn_social_text) +
702
+ "&" + "description=";
703
  }
704
  if ( network == 'twitter' ) {
705
  url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(mlw_qmn_social_text);
mlw_quizmaster2.php CHANGED
@@ -2,14 +2,14 @@
2
  /**
3
  * Plugin Name: Quiz And Survey Master
4
  * Description: Easily and quickly add quizzes and surveys to your website.
5
- * Version: 6.3.0
6
  * Author: QSM Team
7
  * Author URI: https://quizandsurveymaster.com/
8
  * Plugin URI: https://quizandsurveymaster.com/
9
  * Text Domain: quiz-master-next
10
  *
11
  * @author QSM Team
12
- * @version 6.3.0
13
  * @package QSM
14
  */
15
 
@@ -34,7 +34,7 @@ class MLWQuizMasterNext {
34
  * @var string
35
  * @since 4.0.0
36
  */
37
- public $version = '6.3.0';
38
 
39
  /**
40
  * QSM Alert Manager Object
@@ -251,7 +251,7 @@ class MLWQuizMasterNext {
251
  'label' => $plural_name,
252
  'rewrite' => array( 'slug' => $cpt_slug ),
253
  'has_archive' => $has_archive,
254
- 'supports' => array( 'title', 'author', 'comments' )
255
  );
256
 
257
  // Registers post type.
2
  /**
3
  * Plugin Name: Quiz And Survey Master
4
  * Description: Easily and quickly add quizzes and surveys to your website.
5
+ * Version: 6.3.1
6
  * Author: QSM Team
7
  * Author URI: https://quizandsurveymaster.com/
8
  * Plugin URI: https://quizandsurveymaster.com/
9
  * Text Domain: quiz-master-next
10
  *
11
  * @author QSM Team
12
+ * @version 6.3.1
13
  * @package QSM
14
  */
15
 
34
  * @var string
35
  * @since 4.0.0
36
  */
37
+ public $version = '6.3.1';
38
 
39
  /**
40
  * QSM Alert Manager Object
251
  'label' => $plural_name,
252
  'rewrite' => array( 'slug' => $cpt_slug ),
253
  'has_archive' => $has_archive,
254
+ 'supports' => array( 'title', 'author', 'comments', 'thumbnail' )
255
  );
256
 
257
  // Registers post type.
php/admin/options-page-questions-tab.php CHANGED
@@ -119,7 +119,7 @@ function qsm_options_questions_tab_content() {
119
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
120
  <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
121
  <header class="qsm-popup__header">
122
- <h2 class="qsm-popup__title" id="modal-1-title">Edit Question</h2>
123
  <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
124
  </header>
125
  <main class="qsm-popup__content" id="modal-1-content">
@@ -184,6 +184,13 @@ function qsm_options_questions_tab_content() {
184
  <input type="radio" name="category" class="category-radio" id="new_category_new" value="new_category"><label for="new_category_new">New: <input type='text' id='new_category' value='' /></label>
185
  </div>
186
  </div>
 
 
 
 
 
 
 
187
  </div>
188
  </main>
189
  <footer class="qsm-popup__footer">
119
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
120
  <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
121
  <header class="qsm-popup__header">
122
+ <h2 class="qsm-popup__title" id="modal-1-title">Edit Question [ ID: <span id="edit-question-id"></span> ]</h2>
123
  <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
124
  </header>
125
  <main class="qsm-popup__content" id="modal-1-content">
184
  <input type="radio" name="category" class="category-radio" id="new_category_new" value="new_category"><label for="new_category_new">New: <input type='text' id='new_category' value='' /></label>
185
  </div>
186
  </div>
187
+ <div id="required_area" class="qsm-row">
188
+ <label><?php _e( 'Hide Autofill?', 'quiz-master-next' ); ?></label>
189
+ <select name="hide_autofill" id="hide_autofill">
190
+ <option value="0" selected="selected"><?php _e( 'No', 'quiz-master-next' ); ?></option>
191
+ <option value="1"><?php _e( 'Yes', 'quiz-master-next' ); ?></option>
192
+ </select>
193
+ </div>
194
  </div>
195
  </main>
196
  <footer class="qsm-popup__footer">
php/admin/options-page-results-page-tab.php CHANGED
@@ -114,6 +114,9 @@ function qsm_options_results_tab_content() {
114
  <div class="template_variable">
115
  <span class="template_name">%TWITTER_SHARE%</span> - <?php _e('Displays button to share on Twitter.', 'quiz-master-next'); ?>
116
  </div>
 
 
 
117
  <?php do_action('qmn_template_variable_list'); ?>
118
  </div>
119
  <div style="clear:both;"></div>
114
  <div class="template_variable">
115
  <span class="template_name">%TWITTER_SHARE%</span> - <?php _e('Displays button to share on Twitter.', 'quiz-master-next'); ?>
116
  </div>
117
+ <div class="template_variable">
118
+ <span class="template_name">%POLL_RESULTS_X%</span> - <?php _e('X = Question ID Note: only supported for multiple choice answers', 'quiz-master-next'); ?>
119
+ </div>
120
  <?php do_action('qmn_template_variable_list'); ?>
121
  </div>
122
  <div style="clear:both;"></div>
php/admin/quiz-options-page.php CHANGED
@@ -64,6 +64,35 @@ function qsm_generate_quiz_options() {
64
  <div class='mlw_quiz_options'>
65
  <h1 style="display: inline-block;"><?php echo $quiz_name; ?></h1>
66
  <a style="display: inline-block;margin-top: 10px;margin-bottom: 15px;margin-left: 10px;" hre="#" class="edit-quiz-name button button-primary">Edit Name</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  <?php
68
  // Puts all output from tab into ob_get_contents below.
69
  ob_start();
64
  <div class='mlw_quiz_options'>
65
  <h1 style="display: inline-block;"><?php echo $quiz_name; ?></h1>
66
  <a style="display: inline-block;margin-top: 10px;margin-bottom: 15px;margin-left: 10px;" hre="#" class="edit-quiz-name button button-primary">Edit Name</a>
67
+ <?php
68
+ // Get quiz post based on quiz id
69
+ $args = array(
70
+ 'posts_per_page' => 1,
71
+ 'post_type' => 'quiz',
72
+ 'meta_query' => array(
73
+ array(
74
+ 'key' => 'quiz_id',
75
+ 'value' => $quiz_id,
76
+ 'compare' => '=',
77
+ ),
78
+ ),
79
+ );
80
+ $the_query = new WP_Query($args);
81
+
82
+ // The Loop
83
+ $post_permalink = '';
84
+ if ($the_query->have_posts()) {
85
+ while ($the_query->have_posts()) {
86
+ $the_query->the_post();
87
+ $post_permalink = get_the_permalink(get_the_ID());
88
+ }
89
+ /* Restore original Post Data */
90
+ wp_reset_postdata();
91
+ }
92
+ ?>
93
+ <a style="text-decoration: none; position: relative; top: 9px; left: 5px;" target="_blank" href="<?php echo $post_permalink; ?>">
94
+ <span style="font-size: 30px;" class="dashicons dashicons-external"></span>
95
+ </a>
96
  <?php
97
  // Puts all output from tab into ob_get_contents below.
98
  ob_start();
php/classes/class-qmn-quiz-creator.php CHANGED
@@ -435,6 +435,11 @@ class QMNQuizCreator {
435
  )
436
  );
437
  $mlw_new_id = $wpdb->insert_id;
 
 
 
 
 
438
  if ( false != $results ) {
439
  $current_user = wp_get_current_user();
440
  $quiz_post = array(
@@ -516,12 +521,29 @@ class QMNQuizCreator {
516
  '%d'
517
  )
518
  );
 
 
 
 
 
 
 
519
  if ($question_results == false)
520
  {
521
  $mlwQuizMasterNext->alertManager->newAlert(sprintf(__('There has been an error in this action. Please share this with the developer. Error Code: %s', 'quiz-master-next'), '0020'), 'error');
522
  $mlwQuizMasterNext->log_manager->add("Error 0020", $wpdb->last_error.' from '.$wpdb->last_query, 0, 'error');
523
  }
524
  }
 
 
 
 
 
 
 
 
 
 
525
  }
526
  }
527
 
435
  )
436
  );
437
  $mlw_new_id = $wpdb->insert_id;
438
+
439
+ //Update quiz settings
440
+ $update_quiz_settings = unserialize($mlw_qmn_duplicate_data->quiz_settings);
441
+ $update_pages = unserialize($update_quiz_settings['pages']);
442
+
443
  if ( false != $results ) {
444
  $current_user = wp_get_current_user();
445
  $quiz_post = array(
521
  '%d'
522
  )
523
  );
524
+ foreach ($update_pages as $pages_key => $pages_value) {
525
+ foreach ($pages_value as $pages_k_q => $page_q_id) {
526
+ if($page_q_id == $mlw_question->question_id){
527
+ $update_pages[$pages_key][$pages_k_q] = $wpdb->insert_id;
528
+ }
529
+ }
530
+ }
531
  if ($question_results == false)
532
  {
533
  $mlwQuizMasterNext->alertManager->newAlert(sprintf(__('There has been an error in this action. Please share this with the developer. Error Code: %s', 'quiz-master-next'), '0020'), 'error');
534
  $mlwQuizMasterNext->log_manager->add("Error 0020", $wpdb->last_error.' from '.$wpdb->last_query, 0, 'error');
535
  }
536
  }
537
+ $update_quiz_settings['pages'] = serialize($update_pages);
538
+ $wpdb->update(
539
+ $wpdb->prefix . "mlw_quizzes",
540
+ array(
541
+ 'quiz_settings' => serialize($update_quiz_settings),
542
+ ),
543
+ array(
544
+ 'quiz_id' => $mlw_new_id
545
+ )
546
+ );
547
  }
548
  }
549
 
php/classes/class-qmn-quiz-manager.php CHANGED
@@ -4,9 +4,8 @@
4
  *
5
  * @package QSM
6
  */
7
-
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit;
10
  }
11
 
12
  /**
@@ -16,1420 +15,1431 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  */
17
  class QMNQuizManager {
18
 
19
- /**
20
- * Main Construct Function
21
- *
22
- * Call functions within class
23
- *
24
- * @since 4.0.0
25
- * @uses QMNQuizManager::add_hooks() Adds actions to hooks and filters
26
- * @return void
27
- */
28
- public function __construct() {
29
- $this->add_hooks();
30
- }
31
-
32
- /**
33
- * Add Hooks
34
- *
35
- * Adds functions to relavent hooks and filters
36
- *
37
- * @since 4.0.0
38
- * @return void
39
- */
40
- public function add_hooks() {
41
- add_shortcode( 'mlw_quizmaster', array( $this, 'display_shortcode' ) );
42
- add_shortcode( 'qsm', array( $this, 'display_shortcode' ) );
43
- add_action( 'wp_ajax_qmn_process_quiz', array( $this, 'ajax_submit_results' ) );
44
- add_action( 'wp_ajax_nopriv_qmn_process_quiz', array( $this, 'ajax_submit_results' ) );
45
- }
46
-
47
- /**
48
- * Generates Content For Quiz Shortcode
49
- *
50
- * Generates the content for the [mlw_quizmaster] shortcode
51
- *
52
- * @since 4.0.0
53
- * @param array $atts The attributes passed from the shortcode.
54
- * @uses QMNQuizManager:load_questions() Loads questions
55
- * @uses QMNQuizManager:create_answer_array() Prepares answers
56
- * @uses QMNQuizManager:display_quiz() Generates and prepares quiz page
57
- * @uses QMNQuizManager:display_results() Generates and prepares results page
58
- * @return string The content for the shortcode
59
- */
60
- public function display_shortcode( $atts ) {
61
- extract(shortcode_atts(array(
62
- 'quiz' => 0,
63
- 'question_amount' => 0,
64
- ), $atts));
65
-
66
- ob_start();
67
-
68
- global $wpdb;
69
- global $mlwQuizMasterNext;
70
- global $qmn_allowed_visit;
71
- global $qmn_json_data;
72
- $qmn_json_data = array();
73
- $qmn_allowed_visit = true;
74
- $success = $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
75
- if ( false === $success ) {
76
- return __( 'It appears that this quiz is not set up correctly', 'quiz-master-next' );
77
- }
78
- $question_amount = intval( $question_amount );
79
-
80
- // Legacy variable.
81
- global $mlw_qmn_quiz;
82
- $mlw_qmn_quiz = $quiz;
83
-
84
- $return_display = '';
85
- $qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
86
-
87
- // If quiz options isn't found, stop function.
88
- if ( is_null( $qmn_quiz_options ) || empty( $qmn_quiz_options->quiz_name ) ) {
89
- return __( 'It appears that this quiz is not set up correctly', 'quiz-master-next' );
90
- }
91
-
92
- // Loads Quiz Template.
93
- // The quiz_stye is misspelled because it has always been misspelled and fixing it would break many sites :(.
94
- if ( 'default' == $qmn_quiz_options->theme_selected ) {
95
- $return_display .= '<style type="text/css">' . $qmn_quiz_options->quiz_stye . '</style>';
96
- wp_enqueue_style( 'qmn_quiz_style', plugins_url( '../../css/qmn_quiz.css', __FILE__ ) );
97
- } else {
98
- $registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates( $qmn_quiz_options->theme_selected );
99
- // Check direct file first, then check templates folder in plugin, then check templates file in theme.
100
- // If all fails, then load custom styling instead.
101
- if ( $registered_template && file_exists( $registered_template['path'] ) ) {
102
- wp_enqueue_style( 'qmn_quiz_template', $registered_template['path'], array(), $mlwQuizMasterNext->version );
103
- } elseif ( $registered_template && file_exists( plugin_dir_path( __FILE__ ) . '../../templates/' . $registered_template['path'] ) ) {
104
- wp_enqueue_style( 'qmn_quiz_template', plugins_url( '../../templates/' . $registered_template['path'], __FILE__ ), array(), $mlwQuizMasterNext->version );
105
- } elseif ( $registered_template && file_exists( get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'] ) ) {
106
- wp_enqueue_style( 'qmn_quiz_template', get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'], array(), $mlwQuizMasterNext->version );
107
- } else {
108
- echo "<style type='text/css'>{$qmn_quiz_options->quiz_stye}</style>";
109
- }
110
- }
111
-
112
- // Starts to prepare variable array for filters.
113
- $qmn_array_for_variables = array(
114
- 'quiz_id' => $qmn_quiz_options->quiz_id,
115
- 'quiz_name' => $qmn_quiz_options->quiz_name,
116
- 'quiz_system' => $qmn_quiz_options->system,
117
- 'user_ip' => $this->get_user_ip(),
118
- );
119
-
120
- $return_display .= "<script>
121
  if (window.qmn_quiz_data === undefined) {
122
  window.qmn_quiz_data = new Object();
123
  }
124
  </script>";
125
- $qmn_json_data = array(
126
- 'quiz_id' => $qmn_array_for_variables['quiz_id'],
127
- 'quiz_name' => $qmn_array_for_variables['quiz_name'],
128
- 'disable_answer' => $qmn_quiz_options->disable_answer_onselect,
129
- 'ajax_show_correct' => $qmn_quiz_options->ajax_show_correct,
130
- 'progress_bar' => $qmn_quiz_options->progress_bar,
131
- );
132
-
133
- $return_display = apply_filters( 'qmn_begin_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables );
134
-
135
- // Checks if we should be showing quiz or results page.
136
- if ( $qmn_allowed_visit && ! isset( $_POST["complete_quiz"] ) && ! empty( $qmn_quiz_options->quiz_name ) ) {
137
- $return_display .= $this->display_quiz( $qmn_quiz_options, $qmn_array_for_variables, $question_amount );
138
- } elseif ( isset( $_POST["complete_quiz"] ) && 'confirmation' == $_POST["complete_quiz"] && $_POST["qmn_quiz_id"] == $qmn_array_for_variables["quiz_id"] ) {
139
- $return_display .= $this->display_results( $qmn_quiz_options, $qmn_array_for_variables );
140
- }
141
-
142
- $qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables );
143
-
144
- $return_display .= '<script>
145
- window.qmn_quiz_data["' . $qmn_json_data["quiz_id"] . '"] = ' . json_encode( $qmn_json_data ) . '
146
  </script>';
147
 
148
- $return_display .= ob_get_clean();
149
- $return_display = apply_filters( 'qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables );
150
- return $return_display;
151
- }
152
-
153
- /**
154
- * Loads Questions
155
- *
156
- * Retrieves the questions from the database
157
- *
158
- * @since 4.0.0
159
- * @param int $quiz_id The id for the quiz.
160
- * @param array $quiz_options The database row for the quiz.
161
- * @param bool $is_quiz_page If the page being loaded is the quiz page or not.
162
- * @param int $question_amount The amount of questions entered using the shortcode attribute.
163
- * @return array The questions for the quiz
164
- * @deprecated 5.2.0 Use new class: QSM_Questions instead
165
- */
166
- public function load_questions( $quiz_id, $quiz_options, $is_quiz_page, $question_amount = 0 ) {
167
-
168
- // Prepare variables.
169
- global $wpdb;
170
- global $mlwQuizMasterNext;
171
- $questions = array();
172
- $order_by_sql = 'ORDER BY question_order ASC';
173
- $limit_sql = '';
174
-
175
- // Checks if the questions should be randomized.
176
- if ( 1 == $quiz_options->randomness_order || 2 == $quiz_options->randomness_order ) {
177
- $order_by_sql = 'ORDER BY rand()';
178
- }
179
-
180
- // Check if we should load all questions or only a selcted amount.
181
- if ( $is_quiz_page && ( 0 != $quiz_options->question_from_total || 0 !== $question_amount ) ) {
182
- if ( 0 !== $question_amount ) {
183
- $limit_sql = " LIMIT $question_amount";
184
- } else {
185
- $limit_sql = ' LIMIT ' . intval( $quiz_options->question_from_total );
186
- }
187
- }
188
-
189
- // If using newer pages system from 5.2.
190
- $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
191
- // Get all question IDs needed.
192
- $total_pages = count( $pages );
193
- if ( $total_pages > 0 ) {
194
- for ( $i = 0; $i < $total_pages; $i++ ) {
195
- foreach ( $pages[ $i ] as $question ) {
196
- $question_ids[] = intval( $question );
197
- }
198
- }
199
- $question_sql = implode( ', ', $question_ids );
200
- $questions = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}mlw_questions WHERE question_id IN ($question_sql) " . $order_by_sql . $limit_sql );
201
-
202
- // If we are not using randomization, we need to put the questions in the order of the new question editor.
203
- // If a user has saved the pages in the question editor but still uses the older pagination options
204
- // Then they will make it here. So, we need to order the questions based on the new editor.
205
- if ( 1 != $quiz_options->randomness_order && 2 != $quiz_options->randomness_order ) {
206
- $ordered_questions = array();
207
- foreach ( $questions as $question ) {
208
- $key = array_search( $question->question_id, $question_ids );
209
- if ( false !== $key ) {
210
- $ordered_questions[ $key ] = $question;
211
- }
212
- }
213
- ksort( $ordered_questions );
214
- $questions = $ordered_questions;
215
- }
216
- } else {
217
- $questions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "mlw_questions WHERE quiz_id=%d AND deleted=0 " . $order_by_sql . $limit_sql, $quiz_id ) );
218
- }
219
-
220
- // Returns an array of all the loaded questions.
221
- return $questions;
222
- }
223
-
224
- /**
225
- * Prepares Answers
226
- *
227
- * Prepares or creates the answer array for the quiz
228
- *
229
- * @since 4.0.0
230
- * @param array $questions The questions for the quiz.
231
- * @param bool $is_ajax Pass true if this is an ajax call.
232
- * @return array The answers for the quiz
233
- * @deprecated 5.2.0 Use new class: QSM_Questions instead
234
- */
235
- public function create_answer_array( $questions, $is_ajax = false ) {
236
-
237
- // Load and prepare answer arrays.
238
- $mlw_qmn_answer_arrays = array();
239
- $question_list = array();
240
- foreach ( $questions as $mlw_question_info ) {
241
- $question_list[ $mlw_question_info->question_id ] = get_object_vars( $mlw_question_info );
242
- if ( is_serialized( $mlw_question_info->answer_array ) && is_array( @unserialize( $mlw_question_info->answer_array ) ) ) {
243
- $mlw_qmn_answer_array_each = @unserialize( $mlw_question_info->answer_array );
244
- $mlw_qmn_answer_arrays[ $mlw_question_info->question_id ] = $mlw_qmn_answer_array_each;
245
- $question_list[ $mlw_question_info->question_id ]["answers"] = $mlw_qmn_answer_array_each;
246
- } else {
247
- $mlw_answer_array_correct = array(0, 0, 0, 0, 0, 0);
248
- $mlw_answer_array_correct[$mlw_question_info->correct_answer-1] = 1;
249
- $mlw_qmn_answer_arrays[$mlw_question_info->question_id] = array(
250
- array($mlw_question_info->answer_one, $mlw_question_info->answer_one_points, $mlw_answer_array_correct[0]),
251
- array($mlw_question_info->answer_two, $mlw_question_info->answer_two_points, $mlw_answer_array_correct[1]),
252
- array($mlw_question_info->answer_three, $mlw_question_info->answer_three_points, $mlw_answer_array_correct[2]),
253
- array($mlw_question_info->answer_four, $mlw_question_info->answer_four_points, $mlw_answer_array_correct[3]),
254
- array($mlw_question_info->answer_five, $mlw_question_info->answer_five_points, $mlw_answer_array_correct[4]),
255
- array($mlw_question_info->answer_six, $mlw_question_info->answer_six_points, $mlw_answer_array_correct[5]));
256
- $question_list[$mlw_question_info->question_id]["answers"] = $mlw_qmn_answer_arrays[$mlw_question_info->question_id];
257
- }
258
- }
259
- if ( ! $is_ajax ) {
260
- global $qmn_json_data;
261
- $qmn_json_data["question_list"] = $question_list;
262
- }
263
- return $mlw_qmn_answer_arrays;
264
- }
265
-
266
- /**
267
- * Generates Content Quiz Page
268
- *
269
- * Generates the content for the quiz page part of the shortcode
270
- *
271
- * @since 4.0.0
272
- * @param array $options The database row of the quiz.
273
- * @param array $quiz_data The array of results for the quiz.
274
- * @param int $question_amount The number of questions to load for quiz.
275
- * @uses QMNQuizManager:display_begin_section() Creates display for beginning section
276
- * @uses QMNQuizManager:display_questions() Creates display for questions
277
- * @uses QMNQuizManager:display_comment_section() Creates display for comment section
278
- * @uses QMNQuizManager:display_end_section() Creates display for end section
279
- * @return string The content for the quiz page section
280
- */
281
- public function display_quiz( $options, $quiz_data, $question_amount ) {
282
-
283
- global $qmn_allowed_visit;
284
- global $mlwQuizMasterNext;
285
- $quiz_display = '';
286
- $quiz_display = apply_filters( 'qmn_begin_quiz', $quiz_display, $options, $quiz_data );
287
- if ( ! $qmn_allowed_visit ) {
288
- return $quiz_display;
289
- }
290
- wp_enqueue_script( 'json2' );
291
- wp_enqueue_script( 'jquery' );
292
- wp_enqueue_script( 'jquery-ui-core' );
293
- wp_enqueue_script( 'jquery-ui-tooltip' );
294
- wp_enqueue_style( 'jquery-redmond-theme', plugins_url( '../../css/jquery-ui.css', __FILE__ ) );
295
-
296
- global $qmn_json_data;
297
- $qmn_json_data['error_messages'] = array(
298
- 'email' => $options->email_error_text,
299
- 'number' => $options->number_error_text,
300
- 'incorrect' => $options->incorrect_error_text,
301
- 'empty' => $options->empty_error_text,
302
- );
303
-
304
- wp_enqueue_script( 'progress-bar', plugins_url( '../../js/progressbar.min.js', __FILE__ ) );
305
- wp_enqueue_script( 'qsm_quiz', plugins_url( '../../js/qsm-quiz.js', __FILE__ ), array( 'wp-util', 'underscore', 'jquery', 'jquery-ui-tooltip', 'progress-bar' ), $mlwQuizMasterNext->version );
306
- wp_localize_script( 'qsm_quiz', 'qmn_ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
307
- wp_enqueue_script( 'math_jax', '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML' );
308
-
309
- global $qmn_total_questions;
310
- $qmn_total_questions = 0;
311
- global $mlw_qmn_section_count;
312
- $mlw_qmn_section_count = 0;
313
-
314
- $quiz_display .= "<div class='qsm-quiz-container qmn_quiz_container mlw_qmn_quiz'>";
315
- $quiz_display .= apply_filters('qsm_display_before_form', $quiz_display);
316
- $quiz_display .= "<form name='quizForm{$quiz_data['quiz_id']}' id='quizForm{$quiz_data['quiz_id']}' action='' method='post' class='qsm-quiz-form qmn_quiz_form mlw_quiz_form' novalidate >";
317
- $quiz_display .= "<div name='mlw_error_message' id='mlw_error_message' class='qsm-error-message qmn_error_message_section'></div>";
318
- $quiz_display .= "<span id='mlw_top_of_quiz'></span>";
319
- $quiz_display = apply_filters( 'qmn_begin_quiz_form', $quiz_display, $options, $quiz_data );
320
-
321
- // If deprecated pagination setting is not used, use new system...
322
- $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
323
- if ( 0 == $options->randomness_order && 0 == $options->question_from_total && 0 == $options->pagination && 0 !== count( $pages ) ) {
324
- $quiz_display .= $this->display_pages( $options, $quiz_data );
325
- } else {
326
- // ... else, use older system.
327
- $questions = $this->load_questions( $quiz_data['quiz_id'], $options, true, $question_amount );
328
- $answers = $this->create_answer_array( $questions );
329
- $quiz_display .= $this->display_begin_section( $options, $quiz_data );
330
- $quiz_display = apply_filters( 'qmn_begin_quiz_questions', $quiz_display, $options, $quiz_data );
331
- $quiz_display .= $this->display_questions( $options, $questions, $answers );
332
- $quiz_display = apply_filters( 'qmn_before_comment_section', $quiz_display, $options, $quiz_data );
333
- $quiz_display .= $this->display_comment_section( $options, $quiz_data );
334
- $quiz_display = apply_filters( 'qmn_after_comment_section', $quiz_display, $options, $quiz_data );
335
- $quiz_display .= $this->display_end_section( $options, $quiz_data );
336
- }
337
- $quiz_display = apply_filters( 'qmn_before_error_message', $quiz_display, $options, $quiz_data );
338
- $quiz_display .= "<div name='mlw_error_message_bottom' id='mlw_error_message_bottom' class='qsm-error-message qmn_error_message_section'></div>";
339
- $quiz_display .= "<input type='hidden' name='total_questions' id='total_questions' value='$qmn_total_questions'/>";
340
- $quiz_display .= "<input type='hidden' name='timer' id='timer' value='0'/>";
341
- $quiz_display .= "<input type='hidden' class='qmn_quiz_id' name='qmn_quiz_id' id='qmn_quiz_id' value='{$quiz_data['quiz_id']}'/>";
342
- $quiz_display .= "<input type='hidden' name='complete_quiz' value='confirmation' />";
343
- if(isset($_GET['payment_id']) && $_GET['payment_id'] != ''){
344
- $quiz_display .= "<input type='hidden' name='main_payment_id' value='". $_GET['payment_id'] ."' />";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  }
346
- $quiz_display = apply_filters( 'qmn_end_quiz_form', $quiz_display, $options, $quiz_data );
347
- $quiz_display .= '</form>';
348
- $quiz_display .= '</div>';
349
-
350
- $quiz_display = apply_filters( 'qmn_end_quiz', $quiz_display, $options, $quiz_data );
351
- return $quiz_display;
352
- }
353
-
354
- /**
355
- * Creates the pages of content for the quiz/survey
356
- *
357
- * @since 5.2.0
358
- * @param array $options The settings for the quiz.
359
- * @param array $quiz_data The array of quiz data.
360
- * @return string The HTML for the pages
361
- */
362
- public function display_pages( $options, $quiz_data ) {
363
- global $mlwQuizMasterNext;
364
- global $qmn_json_data;
365
- ob_start();
366
- $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
367
- $questions = QSM_Questions::load_questions_by_pages( $options->quiz_id );
368
- $question_list = '';
369
- $contact_fields = QSM_Contact_Manager::load_fields();
370
- if ( count( $pages ) > 1 && ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) ) {
371
- $qmn_json_data['first_page'] = true;
372
- $message_before = wpautop( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ) );
373
- $message_before = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_before, $quiz_data );
374
- ?>
375
- <section class="qsm-page">
376
- <div class="quiz_section quiz_begin">
377
- <div class='qsm-before-message mlw_qmn_message_before'><?php echo $message_before; ?></div>
378
- <?php
379
- if ( 0 == $options->contact_info_location ) {
380
- echo QSM_Contact_Manager::display_fields( $options );
381
- }
382
- ?>
383
- </div>
384
- </section>
385
- <?php
386
- }
387
-
388
- // If there is only one page.
389
- if ( 1 == count( $pages ) ) {
390
- ?>
391
- <section class="qsm-page">
392
- <?php
393
- if ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) {
394
- $qmn_json_data['first_page'] = false;
395
- $message_before = wpautop( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ) );
396
- $message_before = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_before, $quiz_data );
397
- ?>
398
- <div class="quiz_section quiz_begin">
399
- <div class='qsm-before-message mlw_qmn_message_before'><?php echo $message_before; ?></div>
400
- <?php
401
- if ( 0 == $options->contact_info_location ) {
402
- echo QSM_Contact_Manager::display_fields( $options );
403
- }
404
- ?>
405
- </div>
406
- <?php
407
- }
408
- foreach ( $pages[0] as $question_id ) {
409
- $question_list .= $question_id . 'Q';
410
- $question = $questions[ $question_id ];
411
- ?>
412
- <div class='quiz_section question-section-id-<?php echo esc_attr( $question_id ); ?>'>
413
- <?php
414
- echo $mlwQuizMasterNext->pluginHelper->display_question( $question['question_type_new'], $question_id, $options );
415
- if ( 0 == $question['comments'] ) {
416
- echo "<input type='text' class='qsm-question-comment qsm-question-comment-small mlw_qmn_question_comment' x-webkit-speech id='mlwComment$question_id' name='mlwComment$question_id' value='" . esc_attr( htmlspecialchars_decode( $options->comment_field_text, ENT_QUOTES ) ) . "' onclick='qmnClearField(this)'/>";
417
- }
418
- if ( 2 == $question['comments'] ) {
419
- echo "<textarea class='qsm-question-comment qsm-question-comment-large mlw_qmn_question_comment' id='mlwComment$question_id' name='mlwComment$question_id' onclick='qmnClearField(this)'>" . htmlspecialchars_decode( $options->comment_field_text, ENT_QUOTES ) . "</textarea>";
420
- }
421
- // Checks if a hint is entered.
422
- if ( ! empty( $question['hints'] ) ) {
423
- echo '<div title="' . esc_attr( htmlspecialchars_decode( $question['hints'], ENT_QUOTES ) ) . '" class="qsm-hint qsm_hint mlw_qmn_hint_link">' . $options->hint_text . '</div>';
424
- }
425
- ?>
426
- </div>
427
- <?php
428
- }
429
- if ( 0 == $options->comment_section ) {
430
- $message_comments = wpautop( htmlspecialchars_decode( $options->message_comment, ENT_QUOTES ) );
431
- $message_comments = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data );
432
- ?>
433
- <div class="quiz_section quiz_begin">
434
- <label for='mlwQuizComments' class='qsm-comments-label mlw_qmn_comment_section_text'><?php echo $message_comments; ?></label>
435
- <textarea id='mlwQuizComments' name='mlwQuizComments' class='qsm-comments qmn_comment_section'></textarea>
436
- </div>
437
- <?php
438
- }
439
- if ( ! empty( $options->message_end_template ) || ( 1 == $options->contact_info_location && $contact_fields ) ) {
440
- $message_after = wpautop( htmlspecialchars_decode( $options->message_end_template, ENT_QUOTES ) );
441
- $message_after = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data );
442
- ?>
443
- <div class="quiz_section">
444
- <div class='qsm-after-message mlw_qmn_message_end'><?php echo $message_after; ?></div>
445
- <?php
446
- if ( 1 == $options->contact_info_location ) {
447
- echo QSM_Contact_Manager::display_fields( $options );
448
- }
449
- ?>
450
- </div>
451
- <?php
452
- }
453
- ?>
454
- </section>
455
- <?php
456
- } else {
457
- foreach ( $pages as $page ) {
458
- ?>
459
- <section class="qsm-page">
460
- <?php
461
- foreach ( $page as $question_id ) {
462
- $question_list .= $question_id . 'Q';
463
- $question = $questions[ $question_id ];
464
- ?>
465
- <div class='quiz_section question-section-id-<?php echo esc_attr( $question_id ); ?>'>
466
- <?php
467
- echo $mlwQuizMasterNext->pluginHelper->display_question( $question['question_type_new'], $question_id, $options );
468
- if ( 0 == $question['comments'] ) {
469
- echo "<input type='text' class='qsm-question-comment qsm-question-comment-small mlw_qmn_question_comment' x-webkit-speech id='mlwComment$question_id' name='mlwComment$question_id' value='" . esc_attr( htmlspecialchars_decode( $options->comment_field_text, ENT_QUOTES ) ) . "' onclick='qmnClearField(this)'/>";
470
- }
471
- if ( 2 == $question['comments'] ) {
472
- echo "<textarea class='qsm-question-comment qsm-question-comment-large mlw_qmn_question_comment' id='mlwComment$question_id' name='mlwComment$question_id' onclick='qmnClearField(this)'>" . htmlspecialchars_decode( $options->comment_field_text, ENT_QUOTES ) . "</textarea>";
473
- }
474
- // Checks if a hint is entered.
475
- if ( ! empty( $question['hints'] ) ) {
476
- echo '<div title="' . esc_attr( htmlspecialchars_decode( $question['hints'], ENT_QUOTES ) ) . '" class="qsm-hint qsm_hint mlw_qmn_hint_link">' . $options->hint_text . '</div>';
477
- }
478
- ?>
479
- </div>
480
- <?php
481
- }
482
- ?>
483
- </section>
484
- <?php
485
- }
486
- }
487
-
488
- if ( count( $pages ) > 1 && 0 == $options->comment_section ) {
489
- $message_comments = wpautop( htmlspecialchars_decode( $options->message_comment, ENT_QUOTES ) );
490
- $message_comments = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data );
491
- ?>
492
- <section class="qsm-page">
493
- <div class="quiz_section quiz_begin">
494
- <label for='mlwQuizComments' class='qsm-comments-label mlw_qmn_comment_section_text'><?php echo $message_comments; ?></label>
495
- <textarea id='mlwQuizComments' name='mlwQuizComments' class='qsm-comments qmn_comment_section'></textarea>
496
- </div>
497
- </section>
498
- <?php
499
- }
500
- if ( count( $pages ) > 1 && ( ! empty( $options->message_end_template ) || ( 1 == $options->contact_info_location && $contact_fields ) ) ) {
501
- $message_after = wpautop( htmlspecialchars_decode( $options->message_end_template, ENT_QUOTES ) );
502
- $message_after = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data );
503
- ?>
504
- <section class="qsm-page">
505
- <div class="quiz_section">
506
- <div class='qsm-after-message mlw_qmn_message_end'><?php echo $message_after; ?></div>
507
- <?php
508
- if ( 1 == $options->contact_info_location ) {
509
- echo QSM_Contact_Manager::display_fields( $options );
510
- }
511
- ?>
512
- </div>
513
- <?php
514
- // Legacy code.
515
- do_action( 'mlw_qmn_end_quiz_section' );
516
- ?>
517
- </section>
518
- <?php
519
- }
520
- ?>
521
- <!-- View for pagination -->
522
- <script type="text/template" id="tmpl-qsm-pagination">
523
- <div class="qsm-pagination qmn_pagination border margin-bottom">
524
- <a class="qsm-btn qsm-previous qmn_btn mlw_qmn_quiz_link mlw_previous" href="#"><?php echo esc_html( $options->previous_button_text ); ?></a>
525
- <span class="qmn_page_message"></span>
526
- <div class="qmn_page_counter_message"></div>
527
- <div id="qsm-progress-bar" style="display:none;"></div>
528
- <a class="qsm-btn qsm-next qmn_btn mlw_qmn_quiz_link mlw_next" href="#"><?php echo esc_html( $options->next_button_text ); ?></a>
529
- <input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value='<?php echo esc_attr( htmlspecialchars_decode( $options->submit_button_text, ENT_QUOTES ) ); ?>' />
530
- </div>
531
- </script>
532
- <input type='hidden' name='qmn_question_list' value='<?php echo esc_attr( $question_list ); ?>' />
533
- <?php
534
- return ob_get_clean();
535
- }
536
-
537
- /**
538
- * Creates Display For Beginning Section
539
- *
540
- * Generates the content for the beginning section of the quiz page
541
- *
542
- * @since 4.0.0
543
- * @param array $qmn_quiz_options The database row of the quiz.
544
- * @param array $qmn_array_for_variables The array of results for the quiz.
545
- * @return string The content for the beginning section
546
- * @deprecated 5.2.0 Use new page system instead
547
- */
548
- public function display_begin_section( $qmn_quiz_options, $qmn_array_for_variables ) {
549
- $section_display = '';
550
- global $qmn_json_data;
551
- $contact_fields = QSM_Contact_Manager::load_fields();
552
- if ( ! empty( $qmn_quiz_options->message_before ) || ( 0 == $qmn_quiz_options->contact_info_location && $contact_fields ) ) {
553
- $qmn_json_data["first_page"] = true;
554
- global $mlw_qmn_section_count;
555
- $mlw_qmn_section_count +=1;
556
- $section_display .= "<div class='quiz_section quiz_begin slide$mlw_qmn_section_count'>";
557
-
558
- $message_before = wpautop(htmlspecialchars_decode($qmn_quiz_options->message_before, ENT_QUOTES));
559
- $message_before = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_before, $qmn_array_for_variables);
560
-
561
- $section_display .= "<div class='mlw_qmn_message_before'>$message_before</div>";
562
- if ( 0 == $qmn_quiz_options->contact_info_location ) {
563
- $section_display .= QSM_Contact_Manager::display_fields( $qmn_quiz_options );
564
- }
565
- $section_display .= "</div>";
566
- } else {
567
- $qmn_json_data["first_page"] = false;
568
- }
569
- return $section_display;
570
- }
571
-
572
- /**
573
- * Creates Display For Questions
574
- *
575
- * Generates the content for the questions part of the quiz page
576
- *
577
- * @since 4.0.0
578
- * @param array $qmn_quiz_options The database row of the quiz.
579
- * @param array $qmn_quiz_questions The questions of the quiz.
580
- * @param array $qmn_quiz_answers The answers of the quiz.
581
- * @uses QMNPluginHelper:display_question() Displays a question
582
- * @return string The content for the questions section
583
- * @deprecated 5.2.0 Use new page system instead
584
- */
585
- public function display_questions( $qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers ) {
586
- $question_display = '';
587
- global $mlwQuizMasterNext;
588
- global $qmn_total_questions;
589
- global $mlw_qmn_section_count;
590
- $question_id_list = '';
591
- foreach ( $qmn_quiz_questions as $mlw_question ) {
592
- $question_id_list .= $mlw_question->question_id."Q";
593
- $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
594
- $question_display .= "<div class='quiz_section question-section-id-{$mlw_question->question_id} slide{$mlw_qmn_section_count}'>";
595
-
596
- $question_display .= $mlwQuizMasterNext->pluginHelper->display_question( $mlw_question->question_type_new, $mlw_question->question_id, $qmn_quiz_options );
597
-
598
- if ( 0 == $mlw_question->comments ) {
599
- $question_display .= "<input type='text' class='mlw_qmn_question_comment' x-webkit-speech id='mlwComment".$mlw_question->question_id."' name='mlwComment".$mlw_question->question_id."' value='".esc_attr(htmlspecialchars_decode($qmn_quiz_options->comment_field_text, ENT_QUOTES))."' onclick='qmnClearField(this)'/>";
600
- $question_display .= "<br />";
601
- }
602
- if ( 2 == $mlw_question->comments ) {
603
- $question_display .= "<textarea cols='70' rows='5' class='mlw_qmn_question_comment' id='mlwComment".$mlw_question->question_id."' name='mlwComment".$mlw_question->question_id."' onclick='qmnClearField(this)'>".htmlspecialchars_decode($qmn_quiz_options->comment_field_text, ENT_QUOTES)."</textarea>";
604
- $question_display .= "<br />";
605
- }
606
 
607
- // Checks if a hint is entered.
608
- if ( ! empty( $mlw_question->hints ) ) {
609
- $question_display .= "<div title=\"" . esc_attr( htmlspecialchars_decode( $mlw_question->hints, ENT_QUOTES ) ) . "\" class='qsm_hint mlw_qmn_hint_link'>{$qmn_quiz_options->hint_text}</div>";
610
- $question_display .= "<br /><br />";
611
- }
612
- $question_display .= "</div>";
613
- }
614
- $question_display .= "<input type='hidden' name='qmn_question_list' value='$question_id_list' />";
615
- return $question_display;
616
- }
617
-
618
- /**
619
- * Creates Display For Comment Section
620
- *
621
- * Generates the content for the comment section part of the quiz page
622
- *
623
- * @since 4.0.0
624
- * @param array $qmn_quiz_options The database row of the quiz.
625
- * @param array $qmn_array_for_variables The array of results for the quiz.
626
- * @return string The content for the comment section
627
- * @deprecated 5.2.0 Use new page system instead
628
- */
629
- public function display_comment_section( $qmn_quiz_options, $qmn_array_for_variables ) {
630
- global $mlw_qmn_section_count;
631
- $comment_display = '';
632
- if ( 0 == $qmn_quiz_options->comment_section ) {
633
- $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
634
- $comment_display .= "<div class='quiz_section slide".$mlw_qmn_section_count."'>";
635
- $message_comments = wpautop(htmlspecialchars_decode($qmn_quiz_options->message_comment, ENT_QUOTES));
636
- $message_comments = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $qmn_array_for_variables);
637
- $comment_display .= "<label for='mlwQuizComments' class='mlw_qmn_comment_section_text'>$message_comments</label><br />";
638
- $comment_display .= "<textarea cols='60' rows='10' id='mlwQuizComments' name='mlwQuizComments' class='qmn_comment_section'></textarea>";
639
- $comment_display .= "</div>";
640
- }
641
- return $comment_display;
642
- }
643
-
644
- /**
645
- * Creates Display For End Section Of Quiz Page
646
- *
647
- * Generates the content for the end section of the quiz page
648
- *
649
- * @since 4.0.0
650
- * @param array $qmn_quiz_options The database row of the quiz.
651
- * @param array $qmn_array_for_variables The array of results for the quiz.
652
- * @return string The content for the end section
653
- * @deprecated 5.2.0 Use new page system instead
654
- */
655
- public function display_end_section( $qmn_quiz_options, $qmn_array_for_variables ) {
656
- global $mlw_qmn_section_count;
657
- $section_display = '';
658
- $section_display .= '<br />';
659
- $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
660
- $section_display .= "<div class='quiz_section slide$mlw_qmn_section_count quiz_end'>";
661
- if ( ! empty( $qmn_quiz_options->message_end_template ) ) {
662
- $message_end = wpautop( htmlspecialchars_decode( $qmn_quiz_options->message_end_template, ENT_QUOTES ) );
663
- $message_end = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_end, $qmn_array_for_variables );
664
- $section_display .= "<span class='mlw_qmn_message_end'>$message_end</span>";
665
- $section_display .= '<br /><br />';
666
- }
667
- if ( 1 == $qmn_quiz_options->contact_info_location ) {
668
- $section_display .= QSM_Contact_Manager::display_fields( $qmn_quiz_options );
669
- }
670
-
671
- // Legacy Code.
672
- ob_start();
673
- do_action( 'mlw_qmn_end_quiz_section' );
674
- $section_display .= ob_get_contents();
675
- ob_end_clean();
676
-
677
- $section_display .= "<input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value='" . esc_attr( htmlspecialchars_decode( $qmn_quiz_options->submit_button_text, ENT_QUOTES ) ) . "' />";
678
- $section_display .= "</div>";
679
-
680
- return $section_display;
681
- }
682
-
683
- /**
684
- * Generates Content Results Page
685
- *
686
- * Generates the content for the results page part of the shortcode
687
- *
688
- * @since 4.0.0
689
- * @param array $options The database row of the quiz.
690
- * @param array $data The array of results for the quiz.
691
- * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
692
- * @return string The content for the results page section
693
- */
694
- public function display_results( $options, $data ) {
695
- $result = $this->submit_results( $options, $data );
696
- $results_array = $result;
697
- return $results_array['display'];
698
- }
699
-
700
- /**
701
- * Calls the results page from ajax
702
- *
703
- * @since 4.6.0
704
- * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
705
- * @return string The content for the results page section
706
- */
707
- public function ajax_submit_results() {
708
- global $qmn_allowed_visit;
709
- global $mlwQuizMasterNext;
710
- parse_str( $_POST["quizData"], $_POST );
711
- $qmn_allowed_visit = true;
712
- $quiz = intval( $_POST["qmn_quiz_id"] );
713
- $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
714
- $options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
715
- $data = array(
716
- 'quiz_id' => $options->quiz_id,
717
- 'quiz_name' => $options->quiz_name,
718
- 'quiz_system' => $options->system,
719
- 'quiz_payment_id' => isset($_POST['main_payment_id']) ? $_POST['main_payment_id'] : ''
720
- );
721
- echo json_encode( $this->submit_results( $options, $data ) );
722
- die();
723
- }
724
-
725
- /**
726
- * Perform The Quiz/Survey Submission
727
- *
728
- * Prepares and save the results, prepares and send emails, prepare results page
729
- *
730
- * @since 4.6.0
731
- * @param array $qmn_quiz_options The database row of the quiz.
732
- * @param array $qmn_array_for_variables The array of results for the quiz.
733
- * @uses QMNQuizManager:check_answers() Creates display for beginning section
734
- * @uses QMNQuizManager:check_comment_section() Creates display for questions
735
- * @uses QMNQuizManager:display_results_text() Creates display for end section
736
- * @uses QMNQuizManager:display_social() Creates display for comment section
737
- * @uses QMNQuizManager:send_user_email() Creates display for end section
738
- * @uses QMNQuizManager:send_admin_email() Creates display for end section
739
- * @return string The content for the results page section
740
- */
741
- public function submit_results( $qmn_quiz_options, $qmn_array_for_variables ) {
742
- global $qmn_allowed_visit;
743
- $result_display = '';
744
-
745
- $qmn_array_for_variables['user_ip'] = $this->get_user_ip();
746
-
747
- $result_display = apply_filters( 'qmn_begin_results', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
748
- if ( ! $qmn_allowed_visit ) {
749
- return $result_display;
750
- }
751
-
752
- // Gathers contact information.
753
- $qmn_array_for_variables['user_name'] = 'None';
754
- $qmn_array_for_variables['user_business'] = 'None';
755
- $qmn_array_for_variables['user_email'] = 'None';
756
- $qmn_array_for_variables['user_phone'] = 'None';
757
- $contact_responses = QSM_Contact_Manager::process_fields( $qmn_quiz_options );
758
- foreach ( $contact_responses as $field ) {
759
- if ( isset( $field['use'] ) ) {
760
- if ( 'name' === $field['use'] ) {
761
- $qmn_array_for_variables['user_name'] = $field["value"];
762
- }
763
- if ( 'comp' === $field['use'] ) {
764
- $qmn_array_for_variables['user_business'] = $field["value"];
765
- }
766
- if ( 'email' === $field['use'] ) {
767
- $qmn_array_for_variables['user_email'] = $field["value"];
768
- }
769
- if ( 'phone' === $field['use'] ) {
770
- $qmn_array_for_variables['user_phone'] = $field["value"];
771
- }
772
- }
773
- }
774
-
775
- $mlw_qmn_timer = isset($_POST["timer"]) ? intval( $_POST["timer"] ) : 0;
776
- $qmn_array_for_variables['user_id'] = get_current_user_id();
777
- $qmn_array_for_variables['timer'] = $mlw_qmn_timer;
778
- $qmn_array_for_variables['time_taken'] = current_time( 'h:i:s A m/d/Y' );
779
- $qmn_array_for_variables['contact'] = $contact_responses;
780
-
781
- if ( !isset( $_POST["mlw_code_captcha"] ) || ( isset( $_POST["mlw_code_captcha"] ) && $_POST["mlw_user_captcha"] == $_POST["mlw_code_captcha"] ) ) {
782
-
783
- $qmn_array_for_variables = array_merge( $qmn_array_for_variables, $this->check_answers( $qmn_quiz_options, $qmn_array_for_variables ) );
784
- $result_display = apply_filters('qmn_after_check_answers', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
785
- $qmn_array_for_variables['comments'] = $this->check_comment_section($qmn_quiz_options, $qmn_array_for_variables);
786
- $result_display = apply_filters('qmn_after_check_comments', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
787
-
788
- // Determines redirect/results page.
789
- $results_pages = $this->display_results_text( $qmn_quiz_options, $qmn_array_for_variables );
790
- $result_display .= $results_pages['display'];
791
- $result_display = apply_filters('qmn_after_results_text', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
792
-
793
- $result_display .= $this->display_social($qmn_quiz_options, $qmn_array_for_variables);
794
- $result_display = apply_filters('qmn_after_social_media', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
795
-
796
- // If the store responses in database option is set to Yes.
797
- if ( 0 != $qmn_quiz_options->store_responses ) {
798
-
799
- // Creates our results array.
800
- $results_array = array(
801
- intval( $qmn_array_for_variables['timer'] ),
802
- $qmn_array_for_variables['question_answers_array'],
803
- htmlspecialchars( stripslashes( $qmn_array_for_variables['comments'] ), ENT_QUOTES ),
804
- 'contact' => $contact_responses,
805
- );
806
- $results_array = apply_filters( 'qsm_results_array', $results_array, $qmn_array_for_variables );
807
- $serialized_results = serialize( $results_array );
808
-
809
- // Inserts the responses in the database.
810
- global $wpdb;
811
- $table_name = $wpdb->prefix . "mlw_results";
812
- $results_insert = $wpdb->insert(
813
- $table_name,
814
- array(
815
- 'quiz_id' => $qmn_array_for_variables['quiz_id'],
816
- 'quiz_name' => $qmn_array_for_variables['quiz_name'],
817
- 'quiz_system' => $qmn_array_for_variables['quiz_system'],
818
- 'point_score' => $qmn_array_for_variables['total_points'],
819
- 'correct_score' => $qmn_array_for_variables['total_score'],
820
- 'correct' => $qmn_array_for_variables['total_correct'],
821
- 'total' => $qmn_array_for_variables['total_questions'],
822
- 'name' => $qmn_array_for_variables['user_name'],
823
- 'business' => $qmn_array_for_variables['user_business'],
824
- 'email' => $qmn_array_for_variables['user_email'],
825
- 'phone' => $qmn_array_for_variables['user_phone'],
826
- 'user' => $qmn_array_for_variables['user_id'],
827
- 'user_ip' => $qmn_array_for_variables['user_ip'],
828
- 'time_taken' => $qmn_array_for_variables['time_taken'],
829
- 'time_taken_real' => date( 'Y-m-d H:i:s', strtotime( $qmn_array_for_variables['time_taken'] ) ),
830
- 'quiz_results' => $serialized_results,
831
- 'deleted' => 0,
832
- ),
833
- array(
834
- '%d',
835
- '%s',
836
- '%d',
837
- '%d',
838
- '%d',
839
- '%d',
840
- '%d',
841
- '%s',
842
- '%s',
843
- '%s',
844
- '%s',
845
- '%d',
846
- '%s',
847
- '%s',
848
- '%s',
849
- '%s',
850
- '%d',
851
- )
852
- );
853
- }
854
 
855
- $results_id = $wpdb->insert_id;
856
-
857
- // Hook is fired after the responses are submitted. Passes responses, result ID, quiz settings, and response data.
858
- do_action( 'qsm_quiz_submitted', $results_array, $results_id, $qmn_quiz_options, $qmn_array_for_variables );
859
-
860
- // Sends the emails.
861
- QSM_Emails::send_emails( $qmn_array_for_variables );
862
-
863
- /**
864
- * Filters for filtering the results text after emails are sent.
865
- *
866
- * @deprecated 6.2.0 There's no reason to use these over the actions
867
- * in the QSM_Results_Pages class or the other filters in this function.
868
- */
869
- $result_display = apply_filters( 'qmn_after_send_user_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
870
- $result_display = apply_filters( 'qmn_after_send_admin_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
871
-
872
- // Last time to filter the HTML results page.
873
- $result_display = apply_filters( 'qmn_end_results', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
874
-
875
- // Legacy Code.
876
- do_action( 'mlw_qmn_load_results_page', $wpdb->insert_id, $qmn_quiz_options->quiz_settings );
877
- } else {
878
- $result_display .= 'Thank you.';
879
- }
880
-
881
- // Prepares data to be sent back to front-end.
882
- $return_array = array(
883
- 'display' => $result_display,
884
- 'redirect' => $results_pages['redirect'],
885
- );
886
-
887
- return $return_array;
888
- }
889
-
890
- /**
891
- * Scores User Answers
892
- *
893
- * Calculates the users scores for the quiz
894
- *
895
- * @since 4.0.0
896
- * @param array $options The database row of the quiz
897
- * @param array $quiz_data The array of results for the quiz
898
- * @uses QMNPluginHelper:display_review() Scores the question
899
- * @return array The results of the user's score
900
- */
901
- public function check_answers( $options, $quiz_data ) {
902
-
903
- global $mlwQuizMasterNext;
904
-
905
- // Load the pages and questions
906
- $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
907
- $questions = QSM_Questions::load_questions_by_pages( $options->quiz_id );
908
-
909
- // Retrieve data from submission
910
- $total_questions = isset( $_POST["total_questions"] ) ? intval( $_POST["total_questions"] ) : 0;
911
- $question_list = isset( $_POST["qmn_question_list"] ) ? explode( 'Q', $_POST["qmn_question_list"] ) : array();
912
-
913
- // Prepare variables
914
- $points_earned = 0;
915
- $total_correct = 0;
916
- $total_score = 0;
917
- $user_answer = "";
918
- $correct_answer = "";
919
- $correct_status = "incorrect";
920
- $answer_points = 0;
921
- $question_data = array();
922
-
923
- // If deprecated pagination setting is not used, use new system...
924
- if ( 0 == $options->question_from_total && 0 !== count( $pages ) ) {
925
-
926
- // Cycle through each page in quiz.
927
- foreach ( $pages as $page ) {
928
-
929
- // Cycle through each question on a page
930
- foreach ( $page as $page_question_id ) {
931
-
932
- // Cycle through each question that appeared to the user
933
- foreach ( $question_list as $question_id ) {
934
-
935
- // When the questions are the same...
936
- if ( $page_question_id == $question_id ) {
937
-
938
- $question = $questions[ $page_question_id ];
939
-
940
- // Reset question-specific variables
941
- $user_answer = "";
942
- $correct_answer = "";
943
- $correct_status = "incorrect";
944
- $answer_points = 0;
945
-
946
- // Send question to our grading function
947
- $results_array = $mlwQuizMasterNext->pluginHelper->display_review( $question['question_type_new'], $question['question_id'] );
948
-
949
- // If question was graded correctly.
950
- if ( ! isset( $results_array["null_review"] ) ) {
951
- $points_earned += $results_array["points"];
952
- $answer_points += $results_array["points"];
953
-
954
- // If the user's answer was correct
955
- if ( 'correct' == $results_array["correct"] ) {
956
- $total_correct += 1;
957
- $correct_status = "correct";
958
- }
959
- $user_answer = $results_array["user_text"];
960
- $correct_answer = $results_array["correct_text"];
961
-
962
- // If a comment was submitted
963
- if ( isset( $_POST["mlwComment" . $question['question_id'] ] ) ) {
964
- $comment = htmlspecialchars( stripslashes( $_POST["mlwComment" . $question['question_id'] ] ), ENT_QUOTES );
965
- } else {
966
- $comment = "";
967
- }
968
-
969
- // Get text for question
970
- $question_text = $question['question_name'];
971
- if ( isset( $results_array["question_text"] ) ) {
972
- $question_text = $results_array["question_text"];
973
- }
974
-
975
- // Save question data into new array in our array
976
- $question_data[] = apply_filters( 'qmn_answer_array', array(
977
- $question_text,
978
- htmlspecialchars( $user_answer, ENT_QUOTES ),
979
- htmlspecialchars( $correct_answer, ENT_QUOTES ),
980
- $comment,
981
- "correct" => $correct_status,
982
- "id" => $question['question_id'],
983
- "points" => $answer_points,
984
- "category" => $question['category']
985
- ), $options, $quiz_data);
986
- }
987
- break;
988
- }
989
- }
990
- }
991
- }
992
- } else {
993
- // Cycle through each page in quiz.
994
- foreach ( $questions as $question ) {
995
-
996
- // Cycle through each question that appeared to the user
997
- foreach ( $question_list as $question_id ) {
998
-
999
- // When the questions are the same...
1000
- if ( $question['question_id'] == $question_id ) {
1001
-
1002
- // Reset question-specific variables
1003
- $user_answer = "";
1004
- $correct_answer = "";
1005
- $correct_status = "incorrect";
1006
- $answer_points = 0;
1007
-
1008
- // Send question to our grading function
1009
- $results_array = $mlwQuizMasterNext->pluginHelper->display_review( $question['question_type_new'], $question['question_id'] );
1010
-
1011
- // If question was graded correctly.
1012
- if ( ! isset( $results_array["null_review"] ) ) {
1013
- $points_earned += $results_array["points"];
1014
- $answer_points += $results_array["points"];
1015
-
1016
- // If the user's answer was correct
1017
- if ( 'correct' == $results_array["correct"] ) {
1018
- $total_correct += 1;
1019
- $correct_status = "correct";
1020
- }
1021
- $user_answer = $results_array["user_text"];
1022
- $correct_answer = $results_array["correct_text"];
1023
-
1024
- // If a comment was submitted
1025
- if ( isset( $_POST["mlwComment" . $question['question_id'] ] ) ) {
1026
- $comment = htmlspecialchars( stripslashes( $_POST["mlwComment" . $question['question_id'] ] ), ENT_QUOTES );
1027
- } else {
1028
- $comment = "";
1029
- }
1030
-
1031
- // Get text for question
1032
- $question_text = $question['question_name'];
1033
- if ( isset( $results_array["question_text"] ) ) {
1034
- $question_text = $results_array["question_text"];
1035
- }
1036
-
1037
- // Save question data into new array in our array
1038
- $question_data[] = apply_filters( 'qmn_answer_array', array(
1039
- $question_text,
1040
- htmlspecialchars( $user_answer, ENT_QUOTES ),
1041
- htmlspecialchars( $correct_answer, ENT_QUOTES ),
1042
- $comment,
1043
- "correct" => $correct_status,
1044
- "id" => $question['question_id'],
1045
- "points" => $answer_points,
1046
- "category" => $question['category']
1047
- ), $options, $quiz_data);
1048
- }
1049
- break;
1050
- }
1051
- }
1052
- }
1053
- }
1054
-
1055
- // Calculate Total Percent Score And Average Points Only If Total Questions Doesn't Equal Zero To Avoid Division By Zero Error
1056
- if ( 0 !== $total_questions ) {
1057
- $total_score = round( ( ( $total_correct / $total_questions ) * 100 ), 2 );
1058
- } else {
1059
- $total_score = 0;
1060
- }
1061
-
1062
- // Return array to be merged with main user response array
1063
- return array(
1064
- 'total_points' => $points_earned,
1065
- 'total_score' => $total_score,
1066
- 'total_correct' => $total_correct,
1067
- 'total_questions' => $total_questions,
1068
- 'question_answers_display' => '', // Kept for backwards compatibility
1069
- 'question_answers_array' => $question_data,
1070
- );
1071
- }
1072
-
1073
- /**
1074
- * Retrieves User's Comments
1075
- *
1076
- * Checks to see if the user left a comment and returns the comment
1077
- *
1078
- * @since 4.0.0
1079
- * @param array $qmn_quiz_options The database row of the quiz
1080
- * @param array $qmn_array_for_variables The array of results for the quiz
1081
- * @return string The user's comments
1082
- */
1083
- public function check_comment_section($qmn_quiz_options, $qmn_array_for_variables)
1084
- {
1085
- $qmn_quiz_comments = "";
1086
- if ( isset( $_POST["mlwQuizComments"] ) ) {
1087
- $qmn_quiz_comments = esc_textarea( stripslashes( $_POST["mlwQuizComments"] ) );
1088
- }
1089
- return apply_filters( 'qmn_returned_comments', $qmn_quiz_comments, $qmn_quiz_options, $qmn_array_for_variables );
1090
- }
1091
-
1092
-
1093
- /**
1094
- * Displays Results Text
1095
- *
1096
- * @since 4.0.0
1097
- * @deprecated 6.1.0 Use the newer results page class instead.
1098
- * @param array $options The quiz settings.
1099
- * @param array $response_data The array of results for the quiz.
1100
- * @return string The contents for the results text
1101
- */
1102
- public function display_results_text( $options, $response_data ) {
1103
- return QSM_Results_Pages::generate_pages( $response_data );
1104
- }
1105
-
1106
- /**
1107
- * Displays social media buttons
1108
- *
1109
- * @deprecated 6.1.0 Use the social media template variables instead.
1110
- * @since 4.0.0
1111
- * @param array $qmn_quiz_options The database row of the quiz.
1112
- * @param array $qmn_array_for_variables The array of results for the quiz.
1113
- * @return string The content of the social media button section
1114
- */
1115
- public function display_social( $qmn_quiz_options, $qmn_array_for_variables ) {
1116
- $social_display = '';
1117
- if ( $qmn_quiz_options->social_media == 1 ) {
1118
- $settings = (array) get_option( 'qmn-settings' );
1119
- $facebook_app_id = '483815031724529';
1120
- if ( isset( $settings['facebook_app_id'] ) ) {
1121
- $facebook_app_id = esc_js( $settings['facebook_app_id'] );
1122
- }
1123
 
1124
- // Loads Social Media Text.
1125
- $qmn_social_media_text = "";
1126
- if ( is_serialized( $qmn_quiz_options->social_media_text ) && is_array( @unserialize( $qmn_quiz_options->social_media_text ) ) ) {
1127
- $qmn_social_media_text = @unserialize($qmn_quiz_options->social_media_text);
1128
- } else {
1129
- $qmn_social_media_text = array(
1130
- 'twitter' => $qmn_quiz_options->social_media_text,
1131
- 'facebook' => $qmn_quiz_options->social_media_text,
1132
- );
1133
- }
1134
- $qmn_social_media_text["twitter"] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text["twitter"], $qmn_array_for_variables);
1135
- $qmn_social_media_text["facebook"] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text["facebook"], $qmn_array_for_variables);
1136
- $social_display .= "<br />
1137
- <a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('facebook', '".esc_js($qmn_social_media_text["facebook"])."', '".esc_js($qmn_quiz_options->quiz_name)."', '$facebook_app_id');\">Facebook</a>
1138
- <a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('twitter', '".esc_js($qmn_social_media_text["twitter"])."', '".esc_js($qmn_quiz_options->quiz_name)."');\">Twitter</a>
1139
- <br />";
1140
- }
1141
- return apply_filters( 'qmn_returned_social_buttons', $social_display, $qmn_quiz_options, $qmn_array_for_variables );
1142
- }
1143
-
1144
- /**
1145
- * Send User Email
1146
- *
1147
- * Prepares the email to the user and then sends the email
1148
- *
1149
- * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
1150
- * @since 4.0.0
1151
- * @param array $qmn_quiz_options The database row of the quiz
1152
- * @param array $qmn_array_for_variables The array of results for the quiz
1153
- */
1154
- public function send_user_email($qmn_quiz_options, $qmn_array_for_variables)
1155
- {
1156
- add_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
1157
- $mlw_message = "";
1158
-
1159
- //Check if this quiz has user emails turned on
1160
- if ( $qmn_quiz_options->send_user_email == "0" ) {
1161
-
1162
- //Make sure that the user filled in the email field
1163
- if ( $qmn_array_for_variables['user_email'] != "" ) {
1164
-
1165
- //Prepare from email and name
1166
- $from_email_array = maybe_unserialize( $qmn_quiz_options->email_from_text );
1167
- if ( ! isset( $from_email_array["from_email"] ) ) {
1168
- $from_email_array = array(
1169
- 'from_name' => $qmn_quiz_options->email_from_text,
1170
- 'from_email' => $qmn_quiz_options->admin_email,
1171
- 'reply_to' => 1
1172
- );
1173
- }
1174
-
1175
- if ( ! is_email( $from_email_array["from_email"] ) ) {
1176
- if ( is_email( $qmn_quiz_options->admin_email ) ) {
1177
- $from_email_array["from_email"] = $qmn_quiz_options->admin_email;
1178
- } else {
1179
- $from_email_array["from_email"] = get_option( 'admin_email ', 'test@example.com' );
1180
- }
1181
- }
1182
-
1183
- //Prepare email attachments
1184
- $attachments = array();
1185
- $attachments = apply_filters( 'qsm_user_email_attachments', $attachments, $qmn_array_for_variables );
1186
-
1187
- if ( is_serialized( $qmn_quiz_options->user_email_template ) && is_array( @unserialize( $qmn_quiz_options->user_email_template ) ) ) {
1188
-
1189
- $mlw_user_email_array = @unserialize( $qmn_quiz_options->user_email_template );
1190
-
1191
- //Cycle through emails
1192
- foreach( $mlw_user_email_array as $mlw_each ) {
1193
-
1194
- //Generate Email Subject
1195
- if ( !isset( $mlw_each[3] ) ) {
1196
- $mlw_each[3] = "Quiz Results For %QUIZ_NAME";
1197
- }
1198
- $mlw_each[3] = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_each[3], $qmn_array_for_variables );
1199
-
1200
- //Check to see if default
1201
- if ( $mlw_each[0] == 0 && $mlw_each[1] == 0 ) {
1202
- $mlw_message = htmlspecialchars_decode( $mlw_each[2], ENT_QUOTES );
1203
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables );
1204
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message );
1205
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message );
1206
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message );
1207
- $mlw_headers = 'From: '.$from_email_array["from_name"].' <'.$from_email_array["from_email"].'>' . "\r\n";
1208
- wp_mail( $qmn_array_for_variables['user_email'], $mlw_each[3], $mlw_message, $mlw_headers, $attachments );
1209
- break;
1210
- } else {
1211
-
1212
- //Check to see if this quiz uses points and check if the points earned falls in the point range for this email
1213
- if ( $qmn_quiz_options->system == 1 && $qmn_array_for_variables['total_points'] >= $mlw_each[0] && $qmn_array_for_variables['total_points'] <= $mlw_each[1] ) {
1214
- $mlw_message = htmlspecialchars_decode( $mlw_each[2], ENT_QUOTES );
1215
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables );
1216
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message );
1217
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message );
1218
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message );
1219
- $mlw_headers = 'From: '.$from_email_array["from_name"].' <'.$from_email_array["from_email"].'>' . "\r\n";
1220
- wp_mail( $qmn_array_for_variables['user_email'], $mlw_each[3], $mlw_message, $mlw_headers, $attachments );
1221
- break;
1222
- }
1223
-
1224
- //Check to see if score fall in correct range
1225
- if ( $qmn_quiz_options->system == 0 && $qmn_array_for_variables['total_score'] >= $mlw_each[0] && $qmn_array_for_variables['total_score'] <= $mlw_each[1] ) {
1226
- $mlw_message = htmlspecialchars_decode( $mlw_each[2], ENT_QUOTES );
1227
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables );
1228
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message );
1229
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message );
1230
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message );
1231
- $mlw_headers = 'From: '.$from_email_array["from_name"].' <'.$from_email_array["from_email"].'>' . "\r\n";
1232
- wp_mail( $qmn_array_for_variables['user_email'], $mlw_each[3], $mlw_message, $mlw_headers, $attachments );
1233
- break;
1234
- }
1235
- }
1236
- }
1237
- } else {
1238
-
1239
- //Uses older email system still which was before different emails were created.
1240
- $mlw_message = htmlspecialchars_decode( $qmn_quiz_options->user_email_template, ENT_QUOTES );
1241
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables );
1242
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message );
1243
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message );
1244
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message );
1245
- $mlw_headers = 'From: '.$from_email_array["from_name"].' <'.$from_email_array["from_email"].'>' . "\r\n";
1246
- wp_mail( $qmn_array_for_variables['user_email'], "Quiz Results For ".$qmn_quiz_options->quiz_name, $mlw_message, $mlw_headers, $attachments );
1247
- }
1248
- }
1249
- }
1250
- remove_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
1251
- }
1252
-
1253
- /**
1254
- * Send Admin Email
1255
- *
1256
- * Prepares the email to the admin and then sends the email
1257
- *
1258
- * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
1259
- * @since 4.0.0
1260
- * @param array $qmn_quiz_options The database row of the quiz
1261
- * @param arrar $qmn_array_for_variables The array of results for the quiz
1262
- */
1263
- public function send_admin_email($qmn_quiz_options, $qmn_array_for_variables)
1264
- {
1265
- //Switch email type to HTML
1266
- add_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
1267
-
1268
- $mlw_message = "";
1269
- if ( $qmn_quiz_options->send_admin_email == "0" ) {
1270
- if ( $qmn_quiz_options->admin_email != "" ) {
1271
- $from_email_array = maybe_unserialize( $qmn_quiz_options->email_from_text );
1272
- if ( ! isset( $from_email_array["from_email"] ) ) {
1273
- $from_email_array = array(
1274
- 'from_name' => $qmn_quiz_options->email_from_text,
1275
- 'from_email' => $qmn_quiz_options->admin_email,
1276
- 'reply_to' => 1
1277
- );
1278
- }
1279
-
1280
- if ( ! is_email( $from_email_array["from_email"] ) ) {
1281
- if ( is_email( $qmn_quiz_options->admin_email ) ) {
1282
- $from_email_array["from_email"] = $qmn_quiz_options->admin_email;
1283
- } else {
1284
- $from_email_array["from_email"] = get_option( 'admin_email ', 'test@example.com' );
1285
- }
1286
- }
1287
-
1288
- $mlw_message = "";
1289
- $mlw_subject = "";
1290
- if (is_serialized($qmn_quiz_options->admin_email_template) && is_array(@unserialize($qmn_quiz_options->admin_email_template)))
1291
- {
1292
- $mlw_admin_email_array = @unserialize($qmn_quiz_options->admin_email_template);
1293
-
1294
- //Cycle through landing pages
1295
- foreach($mlw_admin_email_array as $mlw_each)
1296
- {
1297
-
1298
- //Generate Email Subject
1299
- if (!isset($mlw_each["subject"]))
1300
- {
1301
- $mlw_each["subject"] = "Quiz Results For %QUIZ_NAME";
1302
- }
1303
- $mlw_each["subject"] = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_each["subject"], $qmn_array_for_variables);
1304
-
1305
- //Check to see if default
1306
- if ($mlw_each["begin_score"] == 0 && $mlw_each["end_score"] == 0)
1307
- {
1308
- $mlw_message = htmlspecialchars_decode($mlw_each["message"], ENT_QUOTES);
1309
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1310
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message);
1311
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message);
1312
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message);
1313
- $mlw_subject = $mlw_each["subject"];
1314
- break;
1315
- }
1316
- else
1317
- {
1318
- //Check to see if points fall in correct range
1319
- if ($qmn_quiz_options->system == 1 && $qmn_array_for_variables['total_points'] >= $mlw_each["begin_score"] && $qmn_array_for_variables['total_points'] <= $mlw_each["end_score"])
1320
- {
1321
- $mlw_message = htmlspecialchars_decode($mlw_each["message"], ENT_QUOTES);
1322
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1323
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message);
1324
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message);
1325
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message);
1326
- $mlw_subject = $mlw_each["subject"];
1327
- break;
1328
- }
1329
-
1330
- //Check to see if score fall in correct range
1331
- if ($qmn_quiz_options->system == 0 && $qmn_array_for_variables['total_score'] >= $mlw_each["begin_score"] && $qmn_array_for_variables['total_score'] <= $mlw_each["end_score"])
1332
- {
1333
- $mlw_message = htmlspecialchars_decode($mlw_each["message"], ENT_QUOTES);
1334
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1335
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message);
1336
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message);
1337
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message);
1338
- $mlw_subject = $mlw_each["subject"];
1339
- break;
1340
- }
1341
- }
1342
- }
1343
- }
1344
- else
1345
- {
1346
- $mlw_message = htmlspecialchars_decode($qmn_quiz_options->admin_email_template, ENT_QUOTES);
1347
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1348
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message);
1349
- $mlw_message = str_replace( "<br/>" , "<br>", $mlw_message);
1350
- $mlw_message = str_replace( "<br />" , "<br>", $mlw_message);
1351
- $mlw_subject = "Quiz Results For ".$qmn_quiz_options->quiz_name;
1352
- }
1353
- }
1354
- if ( get_option('mlw_advert_shows') == 'true' ) {$mlw_message .= "<br>This email was generated by the Quiz And Survey Master plugin";}
1355
- $headers = array(
1356
- 'From: '.$from_email_array["from_name"].' <'.$from_email_array["from_email"].'>'
1357
- );
1358
- if ( $from_email_array["reply_to"] == 0 ) {
1359
- $headers[] = 'Reply-To: '.$qmn_array_for_variables["user_name"]." <".$qmn_array_for_variables["user_email"].">";
1360
- }
1361
- $admin_emails = explode( ",", $qmn_quiz_options->admin_email );
1362
- foreach( $admin_emails as $admin_email ) {
1363
- if ( is_email( $admin_email ) ) {
1364
- wp_mail( $admin_email, $mlw_subject, $mlw_message, $headers );
1365
- }
1366
- }
1367
- }
1368
-
1369
- //Remove HTML type for emails
1370
- remove_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
1371
- }
1372
-
1373
- /**
1374
- * Returns the quiz taker's IP if IP collection is enabled
1375
- *
1376
- * @since 5.3.0
1377
- * @return string The IP address or a phrase if not collected
1378
- */
1379
- private function get_user_ip() {
1380
- $ip = __( 'Not collected', 'quiz-master-next' );
1381
- $settings = (array) get_option( 'qmn-settings' );
1382
- $ip_collection = '0';
1383
- if ( isset( $settings['ip_collection'] ) ) {
1384
- $ip_collection = $settings['ip_collection'];
1385
- }
1386
- if ( '1' != $ip_collection ) {
1387
- if ( $_SERVER['REMOTE_ADDR'] ) {
1388
- $ip = $_SERVER['REMOTE_ADDR'];
1389
- } else {
1390
- $ip = __( 'Unknown', 'quiz-master-next' );
1391
- }
1392
- }
1393
- return $ip;
1394
- }
1395
  }
 
1396
  global $qmnQuizManager;
1397
  $qmnQuizManager = new QMNQuizManager();
1398
 
1399
  add_filter('qmn_begin_shortcode', 'qmn_require_login_check', 10, 3);
1400
- function qmn_require_login_check($display, $qmn_quiz_options, $qmn_array_for_variables)
1401
- {