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
- {
1402
- global $qmn_allowed_visit;
1403
- if ( $qmn_quiz_options->require_log_in == 1 && !is_user_logged_in() )
1404
- {
1405
- $qmn_allowed_visit = false;
1406
- $mlw_message = wpautop(htmlspecialchars_decode($qmn_quiz_options->require_log_in_text, ENT_QUOTES));
1407
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_quiz_page', $mlw_message, $qmn_array_for_variables);
1408
- $mlw_message = str_replace( "\n" , "<br>", $mlw_message);
1409
- $display .= $mlw_message;
1410
- $display .= wp_login_form( array('echo' => false) );
1411
- }
1412
- return $display;
1413
  }
1414
 
1415
- add_filter( 'qmn_begin_shortcode', 'qsm_scheduled_timeframe_check', 10, 3 );
1416
- function qsm_scheduled_timeframe_check( $display, $options, $variable_data ) {
1417
- global $qmn_allowed_visit;
1418
-
1419
- // Checks if the start and end dates have data
1420
- if ( ! empty( $options->scheduled_time_start ) && ! empty( $options->scheduled_time_end ) ) {
1421
- $start = strtotime( $options->scheduled_time_start );
1422
- $end = strtotime( $options->scheduled_time_end ) + 86399;
1423
-
1424
- // Checks if the current timestamp is outside of scheduled timeframe
1425
- if ( current_time( 'timestamp' ) < $start || current_time( 'timestamp' ) > $end ) {
1426
- $qmn_allowed_visit = false;
1427
- $message = wpautop( htmlspecialchars_decode( $options->scheduled_timeframe_text, ENT_QUOTES ) );
1428
- $message = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message, $variable_data );
1429
- $display .= str_replace( "\n" , "<br>", $message );
1430
- }
1431
- }
1432
- return $display;
 
1433
  }
1434
 
1435
  add_filter('qmn_begin_shortcode', 'qmn_total_user_tries_check', 10, 3);
@@ -1443,136 +1453,129 @@ add_filter('qmn_begin_shortcode', 'qmn_total_user_tries_check', 10, 3);
1443
  * @param array $qmn_array_for_variables The array of data by the quiz
1444
  * @return string The altered HTML display for the quiz
1445
  */
1446
- function qmn_total_user_tries_check( $display, $qmn_quiz_options, $qmn_array_for_variables ) {
1447
-
1448
- global $qmn_allowed_visit;
1449
- if ( $qmn_quiz_options->total_user_tries != 0 ) {
1450
-
1451
- // Prepares the variables
1452
- global $wpdb;
1453
- $mlw_qmn_user_try_count = 0;
1454
-
1455
- // Checks if the user is logged in. If so, check by user id. If not, check by IP.
1456
- if ( is_user_logged_in() ) {
1457
- $current_user = wp_get_current_user();
1458
- $mlw_qmn_user_try_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_results WHERE user=%d AND deleted='0' AND quiz_id=%d", $current_user->ID, $qmn_array_for_variables['quiz_id'] ) );
1459
- } else {
1460
- $mlw_qmn_user_try_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_results WHERE user_ip='%s' AND deleted='0' AND quiz_id=%d", $qmn_array_for_variables['user_ip'], $qmn_array_for_variables['quiz_id'] ) );
1461
- }
1462
-
1463
- // If user has already reached the limit for this quiz
1464
- if ( $mlw_qmn_user_try_count >= $qmn_quiz_options->total_user_tries ) {
1465
-
1466
- // Stops the quiz and prepares entered text
1467
- $qmn_allowed_visit = false;
1468
- $mlw_message = wpautop( htmlspecialchars_decode( $qmn_quiz_options->total_user_tries_text, ENT_QUOTES ) );
1469
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_quiz_page', $mlw_message, $qmn_array_for_variables );
1470
- $display .= $mlw_message;
1471
- }
1472
- }
1473
- return $display;
1474
  }
1475
 
1476
  add_filter('qmn_begin_quiz', 'qmn_total_tries_check', 10, 3);
1477
- function qmn_total_tries_check($display, $qmn_quiz_options, $qmn_array_for_variables)
1478
- {
1479
- global $qmn_allowed_visit;
1480
- if ( $qmn_quiz_options->limit_total_entries != 0 )
1481
- {
1482
- global $wpdb;
1483
- $mlw_qmn_entries_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(quiz_id) FROM ".$wpdb->prefix."mlw_results WHERE deleted='0' AND quiz_id=%d", $qmn_array_for_variables['quiz_id'] ) );
1484
- if ($mlw_qmn_entries_count >= $qmn_quiz_options->limit_total_entries)
1485
- {
1486
- $mlw_message = wpautop(htmlspecialchars_decode($qmn_quiz_options->limit_total_entries_text, ENT_QUOTES));
1487
- $mlw_message = apply_filters( 'mlw_qmn_template_variable_quiz_page', $mlw_message, $qmn_array_for_variables);
1488
- $display .= $mlw_message;
1489
- $qmn_allowed_visit = false;
1490
- }
1491
- }
1492
- return $display;
1493
  }
1494
 
1495
  add_filter('qmn_begin_quiz', 'qmn_pagination_check', 10, 3);
1496
- function qmn_pagination_check( $display, $qmn_quiz_options, $qmn_array_for_variables ) {
1497
- if ( $qmn_quiz_options->pagination != 0 ) {
1498
- global $wpdb;
1499
- global $qmn_json_data;
1500
- $total_questions = 0;
1501
- if ( $qmn_quiz_options->question_from_total != 0 ) {
1502
- $total_questions = $qmn_quiz_options->question_from_total;
1503
- } else {
1504
- $questions = QSM_Questions::load_questions_by_pages( $qmn_quiz_options->quiz_id );
1505
- $total_questions = count( $questions );
1506
- }
1507
- $display .= "<style>.quiz_section { display: none; }</style>";
1508
-
1509
- $qmn_json_data["pagination"] = array(
1510
- 'amount' => $qmn_quiz_options->pagination,
1511
- 'section_comments' => $qmn_quiz_options->comment_section,
1512
- 'total_questions' => $total_questions,
1513
- 'previous_text' => $qmn_quiz_options->previous_button_text,
1514
- 'next_text' => $qmn_quiz_options->next_button_text
1515
- );
1516
- }
1517
- return $display;
 
1518
  }
1519
 
1520
- add_filter( 'qmn_begin_quiz_form', 'qmn_timer_check', 15, 3 );
1521
- function qmn_timer_check( $display, $qmn_quiz_options, $qmn_array_for_variables ) {
1522
- global $qmn_allowed_visit;
1523
- global $qmn_json_data;
1524
- if ( $qmn_allowed_visit && $qmn_quiz_options->timer_limit != 0 ) {
1525
- $qmn_json_data["timer_limit"] = $qmn_quiz_options->timer_limit;
1526
- $display .= '<div style="display:none;" id="mlw_qmn_timer" class="mlw_qmn_timer"></div>';
1527
- }
1528
- return $display;
 
1529
  }
1530
 
1531
  add_filter('qmn_begin_quiz', 'qmn_update_views', 10, 3);
1532
- function qmn_update_views($display, $qmn_quiz_options, $qmn_array_for_variables)
1533
- {
1534
- global $wpdb;
1535
- $mlw_views = $qmn_quiz_options->quiz_views;
1536
- $mlw_views += 1;
1537
- $results = $wpdb->update(
1538
- $wpdb->prefix . "mlw_quizzes",
1539
- array(
1540
- 'quiz_views' => $mlw_views
1541
- ),
1542
- array( 'quiz_id' => $qmn_array_for_variables["quiz_id"] ),
1543
- array(
1544
- '%d'
1545
- ),
1546
- array( '%d' )
1547
- );
1548
- return $display;
1549
  }
1550
 
1551
  add_filter('qmn_begin_results', 'qmn_update_taken', 10, 3);
1552
- function qmn_update_taken($display, $qmn_quiz_options, $qmn_array_for_variables)
1553
- {
1554
- global $wpdb;
1555
- $mlw_taken = $qmn_quiz_options->quiz_taken;
1556
- $mlw_taken += 1;
1557
- $results = $wpdb->update(
1558
- $wpdb->prefix . "mlw_quizzes",
1559
- array(
1560
- 'quiz_taken' => $mlw_taken
1561
- ),
1562
- array( 'quiz_id' => $qmn_array_for_variables["quiz_id"] ),
1563
- array(
1564
- '%d'
1565
- ),
1566
- array( '%d' )
1567
- );
1568
- return $display;
1569
  }
1570
 
1571
  /*
1572
- This function helps set the email type to HTML
1573
- */
 
1574
  function mlw_qmn_set_html_content_type() {
1575
 
1576
- return 'text/html';
1577
  }
1578
  ?>
4
  *
5
  * @package QSM
6
  */
7
+ if (!defined('ABSPATH')) {
8
+ exit;
 
9
  }
10
 
11
  /**
15
  */
16
  class QMNQuizManager {
17
 
18
+ /**
19
+ * Main Construct Function
20
+ *
21
+ * Call functions within class
22
+ *
23
+ * @since 4.0.0
24
+ * @uses QMNQuizManager::add_hooks() Adds actions to hooks and filters
25
+ * @return void
26
+ */
27
+ public function __construct() {
28
+ $this->add_hooks();
29
+ }
30
+
31
+ /**
32
+ * Add Hooks
33
+ *
34
+ * Adds functions to relavent hooks and filters
35
+ *
36
+ * @since 4.0.0
37
+ * @return void
38
+ */
39
+ public function add_hooks() {
40
+ add_shortcode('mlw_quizmaster', array($this, 'display_shortcode'));
41
+ add_shortcode('qsm', array($this, 'display_shortcode'));
42
+ add_action('wp_ajax_qmn_process_quiz', array($this, 'ajax_submit_results'));
43
+ add_action('wp_ajax_nopriv_qmn_process_quiz', array($this, 'ajax_submit_results'));
44
+ }
45
+
46
+ /**
47
+ * Generates Content For Quiz Shortcode
48
+ *
49
+ * Generates the content for the [mlw_quizmaster] shortcode
50
+ *
51
+ * @since 4.0.0
52
+ * @param array $atts The attributes passed from the shortcode.
53
+ * @uses QMNQuizManager:load_questions() Loads questions
54
+ * @uses QMNQuizManager:create_answer_array() Prepares answers
55
+ * @uses QMNQuizManager:display_quiz() Generates and prepares quiz page
56
+ * @uses QMNQuizManager:display_results() Generates and prepares results page
57
+ * @return string The content for the shortcode
58
+ */
59
+ public function display_shortcode($atts) {
60
+ extract(shortcode_atts(array(
61
+ 'quiz' => 0,
62
+ 'question_amount' => 0,
63
+ ), $atts));
64
+
65
+ ob_start();
66
+
67
+ global $wpdb;
68
+ global $mlwQuizMasterNext;
69
+ global $qmn_allowed_visit;
70
+ global $qmn_json_data;
71
+ $qmn_json_data = array();
72
+ $qmn_allowed_visit = true;
73
+ $success = $mlwQuizMasterNext->pluginHelper->prepare_quiz($quiz);
74
+ if (false === $success) {
75
+ return __('It appears that this quiz is not set up correctly', 'quiz-master-next');
76
+ }
77
+ $question_amount = intval($question_amount);
78
+
79
+ // Legacy variable.
80
+ global $mlw_qmn_quiz;
81
+ $mlw_qmn_quiz = $quiz;
82
+
83
+ $return_display = '';
84
+ $qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
85
+
86
+ // If quiz options isn't found, stop function.
87
+ if (is_null($qmn_quiz_options) || empty($qmn_quiz_options->quiz_name)) {
88
+ return __('It appears that this quiz is not set up correctly', 'quiz-master-next');
89
+ }
90
+
91
+ // Loads Quiz Template.
92
+ // The quiz_stye is misspelled because it has always been misspelled and fixing it would break many sites :(.
93
+ if ('default' == $qmn_quiz_options->theme_selected) {
94
+ $return_display .= '<style type="text/css">' . $qmn_quiz_options->quiz_stye . '</style>';
95
+ wp_enqueue_style('qmn_quiz_style', plugins_url('../../css/qmn_quiz.css', __FILE__));
96
+ } else {
97
+ $registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates($qmn_quiz_options->theme_selected);
98
+ // Check direct file first, then check templates folder in plugin, then check templates file in theme.
99
+ // If all fails, then load custom styling instead.
100
+ if ($registered_template && file_exists($registered_template['path'])) {
101
+ wp_enqueue_style('qmn_quiz_template', $registered_template['path'], array(), $mlwQuizMasterNext->version);
102
+ } elseif ($registered_template && file_exists(plugin_dir_path(__FILE__) . '../../templates/' . $registered_template['path'])) {
103
+ wp_enqueue_style('qmn_quiz_template', plugins_url('../../templates/' . $registered_template['path'], __FILE__), array(), $mlwQuizMasterNext->version);
104
+ } elseif ($registered_template && file_exists(get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'])) {
105
+ wp_enqueue_style('qmn_quiz_template', get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'], array(), $mlwQuizMasterNext->version);
106
+ } else {
107
+ echo "<style type='text/css'>{$qmn_quiz_options->quiz_stye}</style>";
108
+ }
109
+ }
110
+
111
+ // Starts to prepare variable array for filters.
112
+ $qmn_array_for_variables = array(
113
+ 'quiz_id' => $qmn_quiz_options->quiz_id,
114
+ 'quiz_name' => $qmn_quiz_options->quiz_name,
115
+ 'quiz_system' => $qmn_quiz_options->system,
116
+ 'user_ip' => $this->get_user_ip(),
117
+ );
118
+
119
+ $return_display .= "<script>
120
  if (window.qmn_quiz_data === undefined) {
121
  window.qmn_quiz_data = new Object();
122
  }
123
  </script>";
124
+ $qmn_json_data = array(
125
+ 'quiz_id' => $qmn_array_for_variables['quiz_id'],
126
+ 'quiz_name' => $qmn_array_for_variables['quiz_name'],
127
+ 'disable_answer' => $qmn_quiz_options->disable_answer_onselect,
128
+ 'ajax_show_correct' => $qmn_quiz_options->ajax_show_correct,
129
+ 'progress_bar' => $qmn_quiz_options->progress_bar,
130
+ );
131
+
132
+ $return_display = apply_filters('qmn_begin_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables);
133
+
134
+ // Checks if we should be showing quiz or results page.
135
+ if ($qmn_allowed_visit && !isset($_POST["complete_quiz"]) && !empty($qmn_quiz_options->quiz_name)) {
136
+ $return_display .= $this->display_quiz($qmn_quiz_options, $qmn_array_for_variables, $question_amount);
137
+ } elseif (isset($_POST["complete_quiz"]) && 'confirmation' == $_POST["complete_quiz"] && $_POST["qmn_quiz_id"] == $qmn_array_for_variables["quiz_id"]) {
138
+ $return_display .= $this->display_results($qmn_quiz_options, $qmn_array_for_variables);
139
+ }
140
+
141
+ $qmn_filtered_json = apply_filters('qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables);
142
+
143
+ $return_display .= '<script>
144
+ window.qmn_quiz_data["' . $qmn_json_data["quiz_id"] . '"] = ' . json_encode($qmn_json_data) . '
145
  </script>';
146
 
147
+ $return_display .= ob_get_clean();
148
+ $return_display = apply_filters('qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables);
149
+ return $return_display;
150
+ }
151
+
152
+ /**
153
+ * Loads Questions
154
+ *
155
+ * Retrieves the questions from the database
156
+ *
157
+ * @since 4.0.0
158
+ * @param int $quiz_id The id for the quiz.
159
+ * @param array $quiz_options The database row for the quiz.
160
+ * @param bool $is_quiz_page If the page being loaded is the quiz page or not.
161
+ * @param int $question_amount The amount of questions entered using the shortcode attribute.
162
+ * @return array The questions for the quiz
163
+ * @deprecated 5.2.0 Use new class: QSM_Questions instead
164
+ */
165
+ public function load_questions($quiz_id, $quiz_options, $is_quiz_page, $question_amount = 0) {
166
+
167
+ // Prepare variables.
168
+ global $wpdb;
169
+ global $mlwQuizMasterNext;
170
+ $questions = array();
171
+ $order_by_sql = 'ORDER BY question_order ASC';
172
+ $limit_sql = '';
173
+
174
+ // Checks if the questions should be randomized.
175
+ if (1 == $quiz_options->randomness_order || 2 == $quiz_options->randomness_order) {
176
+ $order_by_sql = 'ORDER BY rand()';
177
+ }
178
+
179
+ // Check if we should load all questions or only a selcted amount.
180
+ if ($is_quiz_page && ( 0 != $quiz_options->question_from_total || 0 !== $question_amount )) {
181
+ if (0 !== $question_amount) {
182
+ $limit_sql = " LIMIT $question_amount";
183
+ } else {
184
+ $limit_sql = ' LIMIT ' . intval($quiz_options->question_from_total);
185
+ }
186
+ }
187
+
188
+ // If using newer pages system from 5.2.
189
+ $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting('pages', array());
190
+ // Get all question IDs needed.
191
+ $total_pages = count($pages);
192
+ if ($total_pages > 0) {
193
+ for ($i = 0; $i < $total_pages; $i++) {
194
+ foreach ($pages[$i] as $question) {
195
+ $question_ids[] = intval($question);
196
+ }
197
+ }
198
+ $question_sql = implode(', ', $question_ids);
199
+ $questions = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}mlw_questions WHERE question_id IN ($question_sql) " . $order_by_sql . $limit_sql);
200
+
201
+ // If we are not using randomization, we need to put the questions in the order of the new question editor.
202
+ // If a user has saved the pages in the question editor but still uses the older pagination options
203
+ // Then they will make it here. So, we need to order the questions based on the new editor.
204
+ if (1 != $quiz_options->randomness_order && 2 != $quiz_options->randomness_order) {
205
+ $ordered_questions = array();
206
+ foreach ($questions as $question) {
207
+ $key = array_search($question->question_id, $question_ids);
208
+ if (false !== $key) {
209
+ $ordered_questions[$key] = $question;
210
+ }
211
+ }
212
+ ksort($ordered_questions);
213
+ $questions = $ordered_questions;
214
+ }
215
+ } else {
216
+ $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));
217
+ }
218
+
219
+ // Returns an array of all the loaded questions.
220
+ return $questions;
221
+ }
222
+
223
+ /**
224
+ * Prepares Answers
225
+ *
226
+ * Prepares or creates the answer array for the quiz
227
+ *
228
+ * @since 4.0.0
229
+ * @param array $questions The questions for the quiz.
230
+ * @param bool $is_ajax Pass true if this is an ajax call.
231
+ * @return array The answers for the quiz
232
+ * @deprecated 5.2.0 Use new class: QSM_Questions instead
233
+ */
234
+ public function create_answer_array($questions, $is_ajax = false) {
235
+
236
+ // Load and prepare answer arrays.
237
+ $mlw_qmn_answer_arrays = array();
238
+ $question_list = array();
239
+ foreach ($questions as $mlw_question_info) {
240
+ $question_list[$mlw_question_info->question_id] = get_object_vars($mlw_question_info);
241
+ if (is_serialized($mlw_question_info->answer_array) && is_array(@unserialize($mlw_question_info->answer_array))) {
242
+ $mlw_qmn_answer_array_each = @unserialize($mlw_question_info->answer_array);
243
+ $mlw_qmn_answer_arrays[$mlw_question_info->question_id] = $mlw_qmn_answer_array_each;
244
+ $question_list[$mlw_question_info->question_id]["answers"] = $mlw_qmn_answer_array_each;
245
+ } else {
246
+ $mlw_answer_array_correct = array(0, 0, 0, 0, 0, 0);
247
+ $mlw_answer_array_correct[$mlw_question_info->correct_answer - 1] = 1;
248
+ $mlw_qmn_answer_arrays[$mlw_question_info->question_id] = array(
249
+ array($mlw_question_info->answer_one, $mlw_question_info->answer_one_points, $mlw_answer_array_correct[0]),
250
+ array($mlw_question_info->answer_two, $mlw_question_info->answer_two_points, $mlw_answer_array_correct[1]),
251
+ array($mlw_question_info->answer_three, $mlw_question_info->answer_three_points, $mlw_answer_array_correct[2]),
252
+ array($mlw_question_info->answer_four, $mlw_question_info->answer_four_points, $mlw_answer_array_correct[3]),
253
+ array($mlw_question_info->answer_five, $mlw_question_info->answer_five_points, $mlw_answer_array_correct[4]),
254
+ array($mlw_question_info->answer_six, $mlw_question_info->answer_six_points, $mlw_answer_array_correct[5]));
255
+ $question_list[$mlw_question_info->question_id]["answers"] = $mlw_qmn_answer_arrays[$mlw_question_info->question_id];
256
+ }
257
+ }
258
+ if (!$is_ajax) {
259
+ global $qmn_json_data;
260
+ $qmn_json_data["question_list"] = $question_list;
261
+ }
262
+ return $mlw_qmn_answer_arrays;
263
+ }
264
+
265
+ /**
266
+ * Generates Content Quiz Page
267
+ *
268
+ * Generates the content for the quiz page part of the shortcode
269
+ *
270
+ * @since 4.0.0
271
+ * @param array $options The database row of the quiz.
272
+ * @param array $quiz_data The array of results for the quiz.
273
+ * @param int $question_amount The number of questions to load for quiz.
274
+ * @uses QMNQuizManager:display_begin_section() Creates display for beginning section
275
+ * @uses QMNQuizManager:display_questions() Creates display for questions
276
+ * @uses QMNQuizManager:display_comment_section() Creates display for comment section
277
+ * @uses QMNQuizManager:display_end_section() Creates display for end section
278
+ * @return string The content for the quiz page section
279
+ */
280
+ public function display_quiz($options, $quiz_data, $question_amount) {
281
+
282
+ global $qmn_allowed_visit;
283
+ global $mlwQuizMasterNext;
284
+ $quiz_display = '';
285
+ $quiz_display = apply_filters('qmn_begin_quiz', $quiz_display, $options, $quiz_data);
286
+ if (!$qmn_allowed_visit) {
287
+ return $quiz_display;
288
+ }
289
+ wp_enqueue_script('json2');
290
+ wp_enqueue_script('jquery');
291
+ wp_enqueue_script('jquery-ui-core');
292
+ wp_enqueue_script('jquery-ui-tooltip');
293
+ wp_enqueue_style('jquery-redmond-theme', plugins_url('../../css/jquery-ui.css', __FILE__));
294
+
295
+ global $qmn_json_data;
296
+ $qmn_json_data['error_messages'] = array(
297
+ 'email' => $options->email_error_text,
298
+ 'number' => $options->number_error_text,
299
+ 'incorrect' => $options->incorrect_error_text,
300
+ 'empty' => $options->empty_error_text,
301
+ );
302
+
303
+ wp_enqueue_script('progress-bar', plugins_url('../../js/progressbar.min.js', __FILE__));
304
+ wp_enqueue_script('qsm_quiz', plugins_url('../../js/qsm-quiz.js', __FILE__), array('wp-util', 'underscore', 'jquery', 'jquery-ui-tooltip', 'progress-bar'), $mlwQuizMasterNext->version);
305
+ wp_localize_script('qsm_quiz', 'qmn_ajax_object', array('ajaxurl' => admin_url('admin-ajax.php')));
306
+ wp_enqueue_script('math_jax', '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML');
307
+
308
+ global $qmn_total_questions;
309
+ $qmn_total_questions = 0;
310
+ global $mlw_qmn_section_count;
311
+ $mlw_qmn_section_count = 0;
312
+
313
+ $quiz_display .= "<div class='qsm-quiz-container qmn_quiz_container mlw_qmn_quiz'>";
314
+ // Get quiz post based on quiz id
315
+ $args = array(
316
+ 'posts_per_page' => 1,
317
+ 'post_type' => 'quiz',
318
+ 'meta_query' => array(
319
+ array(
320
+ 'key' => 'quiz_id',
321
+ 'value' => $quiz_data['quiz_id'],
322
+ 'compare' => '=',
323
+ ),
324
+ ),
325
+ );
326
+ $the_query = new WP_Query($args);
327
+
328
+ // The Loop
329
+ if ($the_query->have_posts()) {
330
+ while ($the_query->have_posts()) {
331
+ $the_query->the_post();
332
+ $quiz_display .= get_the_post_thumbnail(get_the_ID(),'full');
333
+ }
334
+ /* Restore original Post Data */
335
+ wp_reset_postdata();
336
+ }
337
+ $quiz_display .= apply_filters('qsm_display_before_form', $quiz_display);
338
+ $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 >";
339
+ $quiz_display .= "<div name='mlw_error_message' id='mlw_error_message' class='qsm-error-message qmn_error_message_section'></div>";
340
+ $quiz_display .= "<span id='mlw_top_of_quiz'></span>";
341
+ $quiz_display = apply_filters('qmn_begin_quiz_form', $quiz_display, $options, $quiz_data);
342
+
343
+ // If deprecated pagination setting is not used, use new system...
344
+ $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting('pages', array());
345
+ if (0 == $options->randomness_order && 0 == $options->question_from_total && 0 == $options->pagination && 0 !== count($pages)) {
346
+ $quiz_display .= $this->display_pages($options, $quiz_data);
347
+ } else {
348
+ // ... else, use older system.
349
+ $questions = $this->load_questions($quiz_data['quiz_id'], $options, true, $question_amount);
350
+ $answers = $this->create_answer_array($questions);
351
+ $quiz_display .= $this->display_begin_section($options, $quiz_data);
352
+ $quiz_display = apply_filters('qmn_begin_quiz_questions', $quiz_display, $options, $quiz_data);
353
+ $quiz_display .= $this->display_questions($options, $questions, $answers);
354
+ $quiz_display = apply_filters('qmn_before_comment_section', $quiz_display, $options, $quiz_data);
355
+ $quiz_display .= $this->display_comment_section($options, $quiz_data);
356
+ $quiz_display = apply_filters('qmn_after_comment_section', $quiz_display, $options, $quiz_data);
357
+ $quiz_display .= $this->display_end_section($options, $quiz_data);
358
+ }
359
+ $quiz_display = apply_filters('qmn_before_error_message', $quiz_display, $options, $quiz_data);
360
+ $quiz_display .= "<div name='mlw_error_message_bottom' id='mlw_error_message_bottom' class='qsm-error-message qmn_error_message_section'></div>";
361
+ $quiz_display .= "<input type='hidden' name='total_questions' id='total_questions' value='$qmn_total_questions'/>";
362
+ $quiz_display .= "<input type='hidden' name='timer' id='timer' value='0'/>";
363
+ $quiz_display .= "<input type='hidden' class='qmn_quiz_id' name='qmn_quiz_id' id='qmn_quiz_id' value='{$quiz_data['quiz_id']}'/>";
364
+ $quiz_display .= "<input type='hidden' name='complete_quiz' value='confirmation' />";
365
+ if (isset($_GET['payment_id']) && $_GET['payment_id'] != '') {
366
+ $quiz_display .= "<input type='hidden' name='main_payment_id' value='" . $_GET['payment_id'] . "' />";
367
+ }
368
+ $quiz_display = apply_filters('qmn_end_quiz_form', $quiz_display, $options, $quiz_data);
369
+ $quiz_display .= '</form>';
370
+ $quiz_display .= '</div>';
371
+
372
+ $quiz_display = apply_filters('qmn_end_quiz', $quiz_display, $options, $quiz_data);
373
+ return $quiz_display;
374
+ }
375
+
376
+ /**
377
+ * Creates the pages of content for the quiz/survey
378
+ *
379
+ * @since 5.2.0
380
+ * @param array $options The settings for the quiz.
381
+ * @param array $quiz_data The array of quiz data.
382
+ * @return string The HTML for the pages
383
+ */
384
+ public function display_pages($options, $quiz_data) {
385
+ global $mlwQuizMasterNext;
386
+ global $qmn_json_data;
387
+ ob_start();
388
+ $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting('pages', array());
389
+ $questions = QSM_Questions::load_questions_by_pages($options->quiz_id);
390
+ $question_list = '';
391
+ $contact_fields = QSM_Contact_Manager::load_fields();
392
+ if (count($pages) > 1 && (!empty($options->message_before) || ( 0 == $options->contact_info_location && $contact_fields ) )) {
393
+ $qmn_json_data['first_page'] = true;
394
+ $message_before = wpautop(htmlspecialchars_decode($options->message_before, ENT_QUOTES));
395
+ $message_before = apply_filters('mlw_qmn_template_variable_quiz_page', $message_before, $quiz_data);
396
+ ?>
397
+ <section class="qsm-page">
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
+ </section>
407
+ <?php
408
+ }
409
+
410
+ // If there is only one page.
411
+ if (1 == count($pages)) {
412
+ ?>
413
+ <section class="qsm-page">
414
+ <?php
415
+ if (!empty($options->message_before) || ( 0 == $options->contact_info_location && $contact_fields )) {
416
+ $qmn_json_data['first_page'] = false;
417
+ $message_before = wpautop(htmlspecialchars_decode($options->message_before, ENT_QUOTES));
418
+ $message_before = apply_filters('mlw_qmn_template_variable_quiz_page', $message_before, $quiz_data);
419
+ ?>
420
+ <div class="quiz_section quiz_begin">
421
+ <div class='qsm-before-message mlw_qmn_message_before'><?php echo $message_before; ?></div>
422
+ <?php
423
+ if (0 == $options->contact_info_location) {
424
+ echo QSM_Contact_Manager::display_fields($options);
425
+ }
426
+ ?>
427
+ </div>
428
+ <?php
429
+ }
430
+ foreach ($pages[0] as $question_id) {
431
+ $question_list .= $question_id . 'Q';
432
+ $question = $questions[$question_id];
433
+ ?>
434
+ <div class='quiz_section question-section-id-<?php echo esc_attr($question_id); ?>'>
435
+ <?php
436
+ echo $mlwQuizMasterNext->pluginHelper->display_question($question['question_type_new'], $question_id, $options);
437
+ if (0 == $question['comments']) {
438
+ 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)'/>";
439
+ }
440
+ if (2 == $question['comments']) {
441
+ 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>";
442
+ }
443
+ // Checks if a hint is entered.
444
+ if (!empty($question['hints'])) {
445
+ echo '<div title="' . esc_attr(htmlspecialchars_decode($question['hints'], ENT_QUOTES)) . '" class="qsm-hint qsm_hint mlw_qmn_hint_link">' . $options->hint_text . '</div>';
446
+ }
447
+ ?>
448
+ </div>
449
+ <?php
450
+ }
451
+ if (0 == $options->comment_section) {
452
+ $message_comments = wpautop(htmlspecialchars_decode($options->message_comment, ENT_QUOTES));
453
+ $message_comments = apply_filters('mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data);
454
+ ?>
455
+ <div class="quiz_section quiz_begin">
456
+ <label for='mlwQuizComments' class='qsm-comments-label mlw_qmn_comment_section_text'><?php echo $message_comments; ?></label>
457
+ <textarea id='mlwQuizComments' name='mlwQuizComments' class='qsm-comments qmn_comment_section'></textarea>
458
+ </div>
459
+ <?php
460
+ }
461
+ if (!empty($options->message_end_template) || ( 1 == $options->contact_info_location && $contact_fields )) {
462
+ $message_after = wpautop(htmlspecialchars_decode($options->message_end_template, ENT_QUOTES));
463
+ $message_after = apply_filters('mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data);
464
+ ?>
465
+ <div class="quiz_section">
466
+ <div class='qsm-after-message mlw_qmn_message_end'><?php echo $message_after; ?></div>
467
+ <?php
468
+ if (1 == $options->contact_info_location) {
469
+ echo QSM_Contact_Manager::display_fields($options);
470
+ }
471
+ ?>
472
+ </div>
473
+ <?php
474
+ }
475
+ ?>
476
+ </section>
477
+ <?php
478
+ } else {
479
+ foreach ($pages as $page) {
480
+ ?>
481
+ <section class="qsm-page">
482
+ <?php
483
+ foreach ($page as $question_id) {
484
+ $question_list .= $question_id . 'Q';
485
+ $question = $questions[$question_id];
486
+ ?>
487
+ <div class='quiz_section question-section-id-<?php echo esc_attr($question_id); ?>'>
488
+ <?php
489
+ echo $mlwQuizMasterNext->pluginHelper->display_question($question['question_type_new'], $question_id, $options);
490
+ if (0 == $question['comments']) {
491
+ 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)'/>";
492
+ }
493
+ if (2 == $question['comments']) {
494
+ 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>";
495
+ }
496
+ // Checks if a hint is entered.
497
+ if (!empty($question['hints'])) {
498
+ echo '<div title="' . esc_attr(htmlspecialchars_decode($question['hints'], ENT_QUOTES)) . '" class="qsm-hint qsm_hint mlw_qmn_hint_link">' . $options->hint_text . '</div>';
499
+ }
500
+ ?>
501
+ </div>
502
+ <?php
503
+ }
504
+ ?>
505
+ </section>
506
+ <?php
507
+ }
508
+ }
509
+
510
+ if (count($pages) > 1 && 0 == $options->comment_section) {
511
+ $message_comments = wpautop(htmlspecialchars_decode($options->message_comment, ENT_QUOTES));
512
+ $message_comments = apply_filters('mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data);
513
+ ?>
514
+ <section class="qsm-page">
515
+ <div class="quiz_section quiz_begin">
516
+ <label for='mlwQuizComments' class='qsm-comments-label mlw_qmn_comment_section_text'><?php echo $message_comments; ?></label>
517
+ <textarea id='mlwQuizComments' name='mlwQuizComments' class='qsm-comments qmn_comment_section'></textarea>
518
+ </div>
519
+ </section>
520
+ <?php
521
+ }
522
+ if (count($pages) > 1 && (!empty($options->message_end_template) || ( 1 == $options->contact_info_location && $contact_fields ) )) {
523
+ $message_after = wpautop(htmlspecialchars_decode($options->message_end_template, ENT_QUOTES));
524
+ $message_after = apply_filters('mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data);
525
+ ?>
526
+ <section class="qsm-page">
527
+ <div class="quiz_section">
528
+ <div class='qsm-after-message mlw_qmn_message_end'><?php echo $message_after; ?></div>
529
+ <?php
530
+ if (1 == $options->contact_info_location) {
531
+ echo QSM_Contact_Manager::display_fields($options);
532
+ }
533
+ ?>
534
+ </div>
535
+ <?php
536
+ // Legacy code.
537
+ do_action('mlw_qmn_end_quiz_section');
538
+ ?>
539
+ </section>
540
+ <?php
541
+ }
542
+ ?>
543
+ <!-- View for pagination -->
544
+ <script type="text/template" id="tmpl-qsm-pagination">
545
+ <div class="qsm-pagination qmn_pagination border margin-bottom">
546
+ <a class="qsm-btn qsm-previous qmn_btn mlw_qmn_quiz_link mlw_previous" href="#"><?php echo esc_html($options->previous_button_text); ?></a>
547
+ <span class="qmn_page_message"></span>
548
+ <div class="qmn_page_counter_message"></div>
549
+ <div id="qsm-progress-bar" style="display:none;"></div>
550
+ <a class="qsm-btn qsm-next qmn_btn mlw_qmn_quiz_link mlw_next" href="#"><?php echo esc_html($options->next_button_text); ?></a>
551
+ <input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value='<?php echo esc_attr(htmlspecialchars_decode($options->submit_button_text, ENT_QUOTES)); ?>' />
552
+ </div>
553
+ </script>
554
+ <input type='hidden' name='qmn_question_list' value='<?php echo esc_attr($question_list); ?>' />
555
+ <?php
556
+ return ob_get_clean();
557
+ }
558
+
559
+ /**
560
+ * Creates Display For Beginning Section
561
+ *
562
+ * Generates the content for the beginning section of the quiz page
563
+ *
564
+ * @since 4.0.0
565
+ * @param array $qmn_quiz_options The database row of the quiz.
566
+ * @param array $qmn_array_for_variables The array of results for the quiz.
567
+ * @return string The content for the beginning section
568
+ * @deprecated 5.2.0 Use new page system instead
569
+ */
570
+ public function display_begin_section($qmn_quiz_options, $qmn_array_for_variables) {
571
+ $section_display = '';
572
+ global $qmn_json_data;
573
+ $contact_fields = QSM_Contact_Manager::load_fields();
574
+ if (!empty($qmn_quiz_options->message_before) || ( 0 == $qmn_quiz_options->contact_info_location && $contact_fields )) {
575
+ $qmn_json_data["first_page"] = true;
576
+ global $mlw_qmn_section_count;
577
+ $mlw_qmn_section_count += 1;
578
+ $section_display .= "<div class='quiz_section quiz_begin slide$mlw_qmn_section_count'>";
579
+
580
+ $message_before = wpautop(htmlspecialchars_decode($qmn_quiz_options->message_before, ENT_QUOTES));
581
+ $message_before = apply_filters('mlw_qmn_template_variable_quiz_page', $message_before, $qmn_array_for_variables);
582
+
583
+ $section_display .= "<div class='mlw_qmn_message_before'>$message_before</div>";
584
+ if (0 == $qmn_quiz_options->contact_info_location) {
585
+ $section_display .= QSM_Contact_Manager::display_fields($qmn_quiz_options);
586
+ }
587
+ $section_display .= "</div>";
588
+ } else {
589
+ $qmn_json_data["first_page"] = false;
590
+ }
591
+ return $section_display;
592
+ }
593
+
594
+ /**
595
+ * Creates Display For Questions
596
+ *
597
+ * Generates the content for the questions part of the quiz page
598
+ *
599
+ * @since 4.0.0
600
+ * @param array $qmn_quiz_options The database row of the quiz.
601
+ * @param array $qmn_quiz_questions The questions of the quiz.
602
+ * @param array $qmn_quiz_answers The answers of the quiz.
603
+ * @uses QMNPluginHelper:display_question() Displays a question
604
+ * @return string The content for the questions section
605
+ * @deprecated 5.2.0 Use new page system instead
606
+ */
607
+ public function display_questions($qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers) {
608
+ $question_display = '';
609
+ global $mlwQuizMasterNext;
610
+ global $qmn_total_questions;
611
+ global $mlw_qmn_section_count;
612
+ $question_id_list = '';
613
+ foreach ($qmn_quiz_questions as $mlw_question) {
614
+ $question_id_list .= $mlw_question->question_id . "Q";
615
+ $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
616
+ $question_display .= "<div class='quiz_section question-section-id-{$mlw_question->question_id} slide{$mlw_qmn_section_count}'>";
617
+
618
+ $question_display .= $mlwQuizMasterNext->pluginHelper->display_question($mlw_question->question_type_new, $mlw_question->question_id, $qmn_quiz_options);
619
+
620
+ if (0 == $mlw_question->comments) {
621
+ $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)'/>";
622
+ $question_display .= "<br />";
623
+ }
624
+ if (2 == $mlw_question->comments) {
625
+ $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>";
626
+ $question_display .= "<br />";
627
+ }
628
+
629
+ // Checks if a hint is entered.
630
+ if (!empty($mlw_question->hints)) {
631
+ $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>";
632
+ $question_display .= "<br /><br />";
633
+ }
634
+ $question_display .= "</div>";
635
+ }
636
+ $question_display .= "<input type='hidden' name='qmn_question_list' value='$question_id_list' />";
637
+ return $question_display;
638
+ }
639
+
640
+ /**
641
+ * Creates Display For Comment Section
642
+ *
643
+ * Generates the content for the comment section part of the quiz page
644
+ *
645
+ * @since 4.0.0
646
+ * @param array $qmn_quiz_options The database row of the quiz.
647
+ * @param array $qmn_array_for_variables The array of results for the quiz.
648
+ * @return string The content for the comment section
649
+ * @deprecated 5.2.0 Use new page system instead
650
+ */
651
+ public function display_comment_section($qmn_quiz_options, $qmn_array_for_variables) {
652
+ global $mlw_qmn_section_count;
653
+ $comment_display = '';
654
+ if (0 == $qmn_quiz_options->comment_section) {
655
+ $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
656
+ $comment_display .= "<div class='quiz_section slide" . $mlw_qmn_section_count . "'>";
657
+ $message_comments = wpautop(htmlspecialchars_decode($qmn_quiz_options->message_comment, ENT_QUOTES));
658
+ $message_comments = apply_filters('mlw_qmn_template_variable_quiz_page', $message_comments, $qmn_array_for_variables);
659
+ $comment_display .= "<label for='mlwQuizComments' class='mlw_qmn_comment_section_text'>$message_comments</label><br />";
660
+ $comment_display .= "<textarea cols='60' rows='10' id='mlwQuizComments' name='mlwQuizComments' class='qmn_comment_section'></textarea>";
661
+ $comment_display .= "</div>";
662
+ }
663
+ return $comment_display;
664
+ }
665
+
666
+ /**
667
+ * Creates Display For End Section Of Quiz Page
668
+ *
669
+ * Generates the content for the end section of the quiz page
670
+ *
671
+ * @since 4.0.0
672
+ * @param array $qmn_quiz_options The database row of the quiz.
673
+ * @param array $qmn_array_for_variables The array of results for the quiz.
674
+ * @return string The content for the end section
675
+ * @deprecated 5.2.0 Use new page system instead
676
+ */
677
+ public function display_end_section($qmn_quiz_options, $qmn_array_for_variables) {
678
+ global $mlw_qmn_section_count;
679
+ $section_display = '';
680
+ $section_display .= '<br />';
681
+ $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
682
+ $section_display .= "<div class='quiz_section slide$mlw_qmn_section_count quiz_end'>";
683
+ if (!empty($qmn_quiz_options->message_end_template)) {
684
+ $message_end = wpautop(htmlspecialchars_decode($qmn_quiz_options->message_end_template, ENT_QUOTES));
685
+ $message_end = apply_filters('mlw_qmn_template_variable_quiz_page', $message_end, $qmn_array_for_variables);
686
+ $section_display .= "<span class='mlw_qmn_message_end'>$message_end</span>";
687
+ $section_display .= '<br /><br />';
688
+ }
689
+ if (1 == $qmn_quiz_options->contact_info_location) {
690
+ $section_display .= QSM_Contact_Manager::display_fields($qmn_quiz_options);
691
+ }
692
+
693
+ // Legacy Code.
694
+ ob_start();
695
+ do_action('mlw_qmn_end_quiz_section');
696
+ $section_display .= ob_get_contents();
697
+ ob_end_clean();
698
+
699
+ $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)) . "' />";
700
+ $section_display .= "</div>";
701
+
702
+ return $section_display;
703
+ }
704
+
705
+ /**
706
+ * Generates Content Results Page
707
+ *
708
+ * Generates the content for the results page part of the shortcode
709
+ *
710
+ * @since 4.0.0
711
+ * @param array $options The database row of the quiz.
712
+ * @param array $data The array of results for the quiz.
713
+ * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
714
+ * @return string The content for the results page section
715
+ */
716
+ public function display_results($options, $data) {
717
+ $result = $this->submit_results($options, $data);
718
+ $results_array = $result;
719
+ return $results_array['display'];
720
+ }
721
+
722
+ /**
723
+ * Calls the results page from ajax
724
+ *
725
+ * @since 4.6.0
726
+ * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
727
+ * @return string The content for the results page section
728
+ */
729
+ public function ajax_submit_results() {
730
+ global $qmn_allowed_visit;
731
+ global $mlwQuizMasterNext;
732
+ parse_str($_POST["quizData"], $_POST);
733
+ $qmn_allowed_visit = true;
734
+ $quiz = intval($_POST["qmn_quiz_id"]);
735
+ $mlwQuizMasterNext->pluginHelper->prepare_quiz($quiz);
736
+ $options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
737
+ $data = array(
738
+ 'quiz_id' => $options->quiz_id,
739
+ 'quiz_name' => $options->quiz_name,
740
+ 'quiz_system' => $options->system,
741
+ 'quiz_payment_id' => isset($_POST['main_payment_id']) ? $_POST['main_payment_id'] : ''
742
+ );
743
+ echo json_encode($this->submit_results($options, $data));
744
+ die();
745
+ }
746
+
747
+ /**
748
+ * Perform The Quiz/Survey Submission
749
+ *
750
+ * Prepares and save the results, prepares and send emails, prepare results page
751
+ *
752
+ * @since 4.6.0
753
+ * @param array $qmn_quiz_options The database row of the quiz.
754
+ * @param array $qmn_array_for_variables The array of results for the quiz.
755
+ * @uses QMNQuizManager:check_answers() Creates display for beginning section
756
+ * @uses QMNQuizManager:check_comment_section() Creates display for questions
757
+ * @uses QMNQuizManager:display_results_text() Creates display for end section
758
+ * @uses QMNQuizManager:display_social() Creates display for comment section
759
+ * @uses QMNQuizManager:send_user_email() Creates display for end section
760
+ * @uses QMNQuizManager:send_admin_email() Creates display for end section
761
+ * @return string The content for the results page section
762
+ */
763
+ public function submit_results($qmn_quiz_options, $qmn_array_for_variables) {
764
+ global $qmn_allowed_visit;
765
+ $result_display = '';
766
+
767
+ $qmn_array_for_variables['user_ip'] = $this->get_user_ip();
768
+
769
+ $result_display = apply_filters('qmn_begin_results', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
770
+ if (!$qmn_allowed_visit) {
771
+ return $result_display;
772
+ }
773
+
774
+ // Gathers contact information.
775
+ $qmn_array_for_variables['user_name'] = 'None';
776
+ $qmn_array_for_variables['user_business'] = 'None';
777
+ $qmn_array_for_variables['user_email'] = 'None';
778
+ $qmn_array_for_variables['user_phone'] = 'None';
779
+ $contact_responses = QSM_Contact_Manager::process_fields($qmn_quiz_options);
780
+ foreach ($contact_responses as $field) {
781
+ if (isset($field['use'])) {
782
+ if ('name' === $field['use']) {
783
+ $qmn_array_for_variables['user_name'] = $field["value"];
784
+ }
785
+ if ('comp' === $field['use']) {
786
+ $qmn_array_for_variables['user_business'] = $field["value"];
787
+ }
788
+ if ('email' === $field['use']) {
789
+ $qmn_array_for_variables['user_email'] = $field["value"];
790
+ }
791
+ if ('phone' === $field['use']) {
792
+ $qmn_array_for_variables['user_phone'] = $field["value"];
793
+ }
794
+ }
795
+ }
796
+
797
+ $mlw_qmn_timer = isset($_POST["timer"]) ? intval($_POST["timer"]) : 0;
798
+ $qmn_array_for_variables['user_id'] = get_current_user_id();
799
+ $qmn_array_for_variables['timer'] = $mlw_qmn_timer;
800
+ $qmn_array_for_variables['time_taken'] = current_time('h:i:s A m/d/Y');
801
+ $qmn_array_for_variables['contact'] = $contact_responses;
802
+
803
+ if (!isset($_POST["mlw_code_captcha"]) || ( isset($_POST["mlw_code_captcha"]) && $_POST["mlw_user_captcha"] == $_POST["mlw_code_captcha"] )) {
804
+
805
+ $qmn_array_for_variables = array_merge($qmn_array_for_variables, $this->check_answers($qmn_quiz_options, $qmn_array_for_variables));
806
+ $result_display = apply_filters('qmn_after_check_answers', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
807
+ $qmn_array_for_variables['comments'] = $this->check_comment_section($qmn_quiz_options, $qmn_array_for_variables);
808
+ $result_display = apply_filters('qmn_after_check_comments', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
809
+
810
+ // Determines redirect/results page.
811
+ $results_pages = $this->display_results_text($qmn_quiz_options, $qmn_array_for_variables);
812
+ $result_display .= $results_pages['display'];
813
+ $result_display = apply_filters('qmn_after_results_text', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
814
+
815
+ $result_display .= $this->display_social($qmn_quiz_options, $qmn_array_for_variables);
816
+ $result_display = apply_filters('qmn_after_social_media', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
817
+
818
+ // If the store responses in database option is set to Yes.
819
+ if (0 != $qmn_quiz_options->store_responses) {
820
+
821
+ // Creates our results array.
822
+ $results_array = array(
823
+ intval($qmn_array_for_variables['timer']),
824
+ $qmn_array_for_variables['question_answers_array'],
825
+ htmlspecialchars(stripslashes($qmn_array_for_variables['comments']), ENT_QUOTES),
826
+ 'contact' => $contact_responses,
827
+ );
828
+ $results_array = apply_filters('qsm_results_array', $results_array, $qmn_array_for_variables);
829
+ $serialized_results = serialize($results_array);
830
+
831
+ // Inserts the responses in the database.
832
+ global $wpdb;
833
+ $table_name = $wpdb->prefix . "mlw_results";
834
+ $results_insert = $wpdb->insert(
835
+ $table_name, array(
836
+ 'quiz_id' => $qmn_array_for_variables['quiz_id'],
837
+ 'quiz_name' => $qmn_array_for_variables['quiz_name'],
838
+ 'quiz_system' => $qmn_array_for_variables['quiz_system'],
839
+ 'point_score' => $qmn_array_for_variables['total_points'],
840
+ 'correct_score' => $qmn_array_for_variables['total_score'],
841
+ 'correct' => $qmn_array_for_variables['total_correct'],
842
+ 'total' => $qmn_array_for_variables['total_questions'],
843
+ 'name' => $qmn_array_for_variables['user_name'],
844
+ 'business' => $qmn_array_for_variables['user_business'],
845
+ 'email' => $qmn_array_for_variables['user_email'],
846
+ 'phone' => $qmn_array_for_variables['user_phone'],
847
+ 'user' => $qmn_array_for_variables['user_id'],
848
+ 'user_ip' => $qmn_array_for_variables['user_ip'],
849
+ 'time_taken' => $qmn_array_for_variables['time_taken'],
850
+ 'time_taken_real' => date('Y-m-d H:i:s', strtotime($qmn_array_for_variables['time_taken'])),
851
+ 'quiz_results' => $serialized_results,
852
+ 'deleted' => 0,
853
+ ), array(
854
+ '%d',
855
+ '%s',
856
+ '%d',
857
+ '%d',
858
+ '%d',
859
+ '%d',
860
+ '%d',
861
+ '%s',
862
+ '%s',
863
+ '%s',
864
+ '%s',
865
+ '%d',
866
+ '%s',
867
+ '%s',
868
+ '%s',
869
+ '%s',
870
+ '%d',
871
+ )
872
+ );
873
+ }
874
+
875
+ $results_id = $wpdb->insert_id;
876
+
877
+ // Hook is fired after the responses are submitted. Passes responses, result ID, quiz settings, and response data.
878
+ do_action('qsm_quiz_submitted', $results_array, $results_id, $qmn_quiz_options, $qmn_array_for_variables);
879
+
880
+ // Sends the emails.
881
+ QSM_Emails::send_emails($qmn_array_for_variables);
882
+
883
+ /**
884
+ * Filters for filtering the results text after emails are sent.
885
+ *
886
+ * @deprecated 6.2.0 There's no reason to use these over the actions
887
+ * in the QSM_Results_Pages class or the other filters in this function.
888
+ */
889
+ $result_display = apply_filters('qmn_after_send_user_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
890
+ $result_display = apply_filters('qmn_after_send_admin_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
891
+
892
+ // Last time to filter the HTML results page.
893
+ $result_display = apply_filters('qmn_end_results', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
894
+
895
+ // Legacy Code.
896
+ do_action('mlw_qmn_load_results_page', $wpdb->insert_id, $qmn_quiz_options->quiz_settings);
897
+ } else {
898
+ $result_display .= 'Thank you.';
899
+ }
900
+
901
+ // Prepares data to be sent back to front-end.
902
+ $return_array = array(
903
+ 'display' => htmlspecialchars_decode($result_display),
904
+ 'redirect' => $results_pages['redirect'],
905
+ );
906
+
907
+ return $return_array;
908
+ }
909
+
910
+ /**
911
+ * Scores User Answers
912
+ *
913
+ * Calculates the users scores for the quiz
914
+ *
915
+ * @since 4.0.0
916
+ * @param array $options The database row of the quiz
917
+ * @param array $quiz_data The array of results for the quiz
918
+ * @uses QMNPluginHelper:display_review() Scores the question
919
+ * @return array The results of the user's score
920
+ */
921
+ public function check_answers($options, $quiz_data) {
922
+
923
+ global $mlwQuizMasterNext;
924
+
925
+ // Load the pages and questions
926
+ $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting('pages', array());
927
+ $questions = QSM_Questions::load_questions_by_pages($options->quiz_id);
928
+
929
+ // Retrieve data from submission
930
+ $total_questions = isset($_POST["total_questions"]) ? intval($_POST["total_questions"]) : 0;
931
+ $question_list = isset($_POST["qmn_question_list"]) ? explode('Q', $_POST["qmn_question_list"]) : array();
932
+
933
+ // Prepare variables
934
+ $points_earned = 0;
935
+ $total_correct = 0;
936
+ $total_score = 0;
937
+ $user_answer = "";
938
+ $correct_answer = "";
939
+ $correct_status = "incorrect";
940
+ $answer_points = 0;
941
+ $question_data = array();
942
+
943
+ // If deprecated pagination setting is not used, use new system...
944
+ if (0 == $options->question_from_total && 0 !== count($pages)) {
945
+
946
+ // Cycle through each page in quiz.
947
+ foreach ($pages as $page) {
948
+
949
+ // Cycle through each question on a page
950
+ foreach ($page as $page_question_id) {
951
+
952
+ // Cycle through each question that appeared to the user
953
+ foreach ($question_list as $question_id) {
954
+
955
+ // When the questions are the same...
956
+ if ($page_question_id == $question_id) {
957
+
958
+ $question = $questions[$page_question_id];
959
+
960
+ // Reset question-specific variables
961
+ $user_answer = "";
962
+ $correct_answer = "";
963
+ $correct_status = "incorrect";
964
+ $answer_points = 0;
965
+
966
+ // Send question to our grading function
967
+ $results_array = $mlwQuizMasterNext->pluginHelper->display_review($question['question_type_new'], $question['question_id']);
968
+
969
+ // If question was graded correctly.
970
+ if (!isset($results_array["null_review"])) {
971
+ $points_earned += $results_array["points"];
972
+ $answer_points += $results_array["points"];
973
+
974
+ // If the user's answer was correct
975
+ if ('correct' == $results_array["correct"]) {
976
+ $total_correct += 1;
977
+ $correct_status = "correct";
978
+ }
979
+ $user_answer = $results_array["user_text"];
980
+ $correct_answer = $results_array["correct_text"];
981
+
982
+ // If a comment was submitted
983
+ if (isset($_POST["mlwComment" . $question['question_id']])) {
984
+ $comment = htmlspecialchars(stripslashes($_POST["mlwComment" . $question['question_id']]), ENT_QUOTES);
985
+ } else {
986
+ $comment = "";
987
+ }
988
+
989
+ // Get text for question
990
+ $question_text = $question['question_name'];
991
+ if (isset($results_array["question_text"])) {
992
+ $question_text = $results_array["question_text"];
993
+ }
994
+
995
+ // Save question data into new array in our array
996
+ $question_data[] = apply_filters('qmn_answer_array', array(
997
+ $question_text,
998
+ htmlspecialchars($user_answer, ENT_QUOTES),
999
+ htmlspecialchars($correct_answer, ENT_QUOTES),
1000
+ $comment,
1001
+ "correct" => $correct_status,
1002
+ "id" => $question['question_id'],
1003
+ "points" => $answer_points,
1004
+ "category" => $question['category']
1005
+ ), $options, $quiz_data);
1006
+ }
1007
+ break;
1008
+ }
1009
+ }
1010
+ }
1011
+ }
1012
+ } else {
1013
+ // Cycle through each page in quiz.
1014
+ foreach ($questions as $question) {
1015
+
1016
+ // Cycle through each question that appeared to the user
1017
+ foreach ($question_list as $question_id) {
1018
+
1019
+ // When the questions are the same...
1020
+ if ($question['question_id'] == $question_id) {
1021
+
1022
+ // Reset question-specific variables
1023
+ $user_answer = "";
1024
+ $correct_answer = "";
1025
+ $correct_status = "incorrect";
1026
+ $answer_points = 0;
1027
+
1028
+ // Send question to our grading function
1029
+ $results_array = $mlwQuizMasterNext->pluginHelper->display_review($question['question_type_new'], $question['question_id']);
1030
+
1031
+ // If question was graded correctly.
1032
+ if (!isset($results_array["null_review"])) {
1033
+ $points_earned += $results_array["points"];
1034
+ $answer_points += $results_array["points"];
1035
+
1036
+ // If the user's answer was correct
1037
+ if ('correct' == $results_array["correct"]) {
1038
+ $total_correct += 1;
1039
+ $correct_status = "correct";
1040
+ }
1041
+ $user_answer = $results_array["user_text"];
1042
+ $correct_answer = $results_array["correct_text"];
1043
+
1044
+ // If a comment was submitted
1045
+ if (isset($_POST["mlwComment" . $question['question_id']])) {
1046
+ $comment = htmlspecialchars(stripslashes($_POST["mlwComment" . $question['question_id']]), ENT_QUOTES);
1047
+ } else {
1048
+ $comment = "";
1049
+ }
1050
+
1051
+ // Get text for question
1052
+ $question_text = $question['question_name'];
1053
+ if (isset($results_array["question_text"])) {
1054
+ $question_text = $results_array["question_text"];
1055
+ }
1056
+
1057
+ // Save question data into new array in our array
1058
+ $question_data[] = apply_filters('qmn_answer_array', array(
1059
+ $question_text,
1060
+ htmlspecialchars($user_answer, ENT_QUOTES),
1061
+ htmlspecialchars($correct_answer, ENT_QUOTES),
1062
+ $comment,
1063
+ "correct" => $correct_status,
1064
+ "id" => $question['question_id'],
1065
+ "points" => $answer_points,
1066
+ "category" => $question['category']
1067
+ ), $options, $quiz_data);
1068
+ }
1069
+ break;
1070
+ }
1071
+ }
1072
+ }
1073
+ }
1074
+
1075
+ // Calculate Total Percent Score And Average Points Only If Total Questions Doesn't Equal Zero To Avoid Division By Zero Error
1076
+ if (0 !== $total_questions) {
1077
+ $total_score = round(( ( $total_correct / $total_questions ) * 100), 2);
1078
+ } else {
1079
+ $total_score = 0;
1080
+ }
1081
+
1082
+ // Return array to be merged with main user response array
1083
+ return array(
1084
+ 'total_points' => $points_earned,
1085
+ 'total_score' => $total_score,
1086
+ 'total_correct' => $total_correct,
1087
+ 'total_questions' => $total_questions,
1088
+ 'question_answers_display' => '', // Kept for backwards compatibility
1089
+ 'question_answers_array' => $question_data,
1090
+ );
1091
+ }
1092
+
1093
+ /**
1094
+ * Retrieves User's Comments
1095
+ *
1096
+ * Checks to see if the user left a comment and returns the comment
1097
+ *
1098
+ * @since 4.0.0
1099
+ * @param array $qmn_quiz_options The database row of the quiz
1100
+ * @param array $qmn_array_for_variables The array of results for the quiz
1101
+ * @return string The user's comments
1102
+ */
1103
+ public function check_comment_section($qmn_quiz_options, $qmn_array_for_variables) {
1104
+ $qmn_quiz_comments = "";
1105
+ if (isset($_POST["mlwQuizComments"])) {
1106
+ $qmn_quiz_comments = esc_textarea(stripslashes($_POST["mlwQuizComments"]));
1107
+ }
1108
+ return apply_filters('qmn_returned_comments', $qmn_quiz_comments, $qmn_quiz_options, $qmn_array_for_variables);
1109
+ }
1110
+
1111
+ /**
1112
+ * Displays Results Text
1113
+ *
1114
+ * @since 4.0.0
1115
+ * @deprecated 6.1.0 Use the newer results page class instead.
1116
+ * @param array $options The quiz settings.
1117
+ * @param array $response_data The array of results for the quiz.
1118
+ * @return string The contents for the results text
1119
+ */
1120
+ public function display_results_text($options, $response_data) {
1121
+ return QSM_Results_Pages::generate_pages($response_data);
1122
+ }
1123
+
1124
+ /**
1125
+ * Displays social media buttons
1126
+ *
1127
+ * @deprecated 6.1.0 Use the social media template variables instead.
1128
+ * @since 4.0.0
1129
+ * @param array $qmn_quiz_options The database row of the quiz.
1130
+ * @param array $qmn_array_for_variables The array of results for the quiz.
1131
+ * @return string The content of the social media button section
1132
+ */
1133
+ public function display_social($qmn_quiz_options, $qmn_array_for_variables) {
1134
+ $social_display = '';
1135
+ if ($qmn_quiz_options->social_media == 1) {
1136
+ $settings = (array) get_option('qmn-settings');
1137
+ $facebook_app_id = '483815031724529';
1138
+ if (isset($settings['facebook_app_id'])) {
1139
+ $facebook_app_id = esc_js($settings['facebook_app_id']);
1140
+ }
1141
+
1142
+ // Loads Social Media Text.
1143
+ $qmn_social_media_text = "";
1144
+ if (is_serialized($qmn_quiz_options->social_media_text) && is_array(@unserialize($qmn_quiz_options->social_media_text))) {
1145
+ $qmn_social_media_text = @unserialize($qmn_quiz_options->social_media_text);
1146
+ } else {
1147
+ $qmn_social_media_text = array(
1148
+ 'twitter' => $qmn_quiz_options->social_media_text,
1149
+ 'facebook' => $qmn_quiz_options->social_media_text,
1150
+ );
1151
+ }
1152
+ $qmn_social_media_text["twitter"] = apply_filters('mlw_qmn_template_variable_results_page', $qmn_social_media_text["twitter"], $qmn_array_for_variables);
1153
+ $qmn_social_media_text["facebook"] = apply_filters('mlw_qmn_template_variable_results_page', $qmn_social_media_text["facebook"], $qmn_array_for_variables);
1154
+ $social_display .= "<br />
1155
+ <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>
1156
+ <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>
1157
+ <br />";
1158
+ }
1159
+ return apply_filters('qmn_returned_social_buttons', $social_display, $qmn_quiz_options, $qmn_array_for_variables);
1160
+ }
1161
+
1162
+ /**
1163
+ * Send User Email
1164
+ *
1165
+ * Prepares the email to the user and then sends the email
1166
+ *
1167
+ * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
1168
+ * @since 4.0.0
1169
+ * @param array $qmn_quiz_options The database row of the quiz
1170
+ * @param array $qmn_array_for_variables The array of results for the quiz
1171
+ */
1172
+ public function send_user_email($qmn_quiz_options, $qmn_array_for_variables) {
1173
+ add_filter('wp_mail_content_type', 'mlw_qmn_set_html_content_type');
1174
+ $mlw_message = "";
1175
+
1176
+ //Check if this quiz has user emails turned on
1177
+ if ($qmn_quiz_options->send_user_email == "0") {
1178
+
1179
+ //Make sure that the user filled in the email field
1180
+ if ($qmn_array_for_variables['user_email'] != "") {
1181
+
1182
+ //Prepare from email and name
1183
+ $from_email_array = maybe_unserialize($qmn_quiz_options->email_from_text);
1184
+ if (!isset($from_email_array["from_email"])) {
1185
+ $from_email_array = array(
1186
+ 'from_name' => $qmn_quiz_options->email_from_text,
1187
+ 'from_email' => $qmn_quiz_options->admin_email,
1188
+ 'reply_to' => 1
1189
+ );
1190
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1191
 
1192
+ if (!is_email($from_email_array["from_email"])) {
1193
+ if (is_email($qmn_quiz_options->admin_email)) {
1194
+ $from_email_array["from_email"] = $qmn_quiz_options->admin_email;
1195
+ } else {
1196
+ $from_email_array["from_email"] = get_option('admin_email ', 'test@example.com');
1197
+ }
1198
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1199
 
1200
+ //Prepare email attachments
1201
+ $attachments = array();
1202
+ $attachments = apply_filters('qsm_user_email_attachments', $attachments, $qmn_array_for_variables);
1203
+
1204
+ if (is_serialized($qmn_quiz_options->user_email_template) && is_array(@unserialize($qmn_quiz_options->user_email_template))) {
1205
+
1206
+ $mlw_user_email_array = @unserialize($qmn_quiz_options->user_email_template);
1207
+
1208
+ //Cycle through emails
1209
+ foreach ($mlw_user_email_array as $mlw_each) {
1210
+
1211
+ //Generate Email Subject
1212
+ if (!isset($mlw_each[3])) {
1213
+ $mlw_each[3] = "Quiz Results For %QUIZ_NAME";
1214
+ }
1215
+ $mlw_each[3] = apply_filters('mlw_qmn_template_variable_results_page', $mlw_each[3], $qmn_array_for_variables);
1216
+
1217
+ //Check to see if default
1218
+ if ($mlw_each[0] == 0 && $mlw_each[1] == 0) {
1219
+ $mlw_message = htmlspecialchars_decode($mlw_each[2], ENT_QUOTES);
1220
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1221
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1222
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1223
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1224
+ $mlw_headers = 'From: ' . $from_email_array["from_name"] . ' <' . $from_email_array["from_email"] . '>' . "\r\n";
1225
+ wp_mail($qmn_array_for_variables['user_email'], $mlw_each[3], $mlw_message, $mlw_headers, $attachments);
1226
+ break;
1227
+ } else {
1228
+
1229
+ //Check to see if this quiz uses points and check if the points earned falls in the point range for this email
1230
+ if ($qmn_quiz_options->system == 1 && $qmn_array_for_variables['total_points'] >= $mlw_each[0] && $qmn_array_for_variables['total_points'] <= $mlw_each[1]) {
1231
+ $mlw_message = htmlspecialchars_decode($mlw_each[2], ENT_QUOTES);
1232
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1233
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1234
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1235
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1236
+ $mlw_headers = 'From: ' . $from_email_array["from_name"] . ' <' . $from_email_array["from_email"] . '>' . "\r\n";
1237
+ wp_mail($qmn_array_for_variables['user_email'], $mlw_each[3], $mlw_message, $mlw_headers, $attachments);
1238
+ break;
1239
+ }
1240
+
1241
+ //Check to see if score fall in correct range
1242
+ if ($qmn_quiz_options->system == 0 && $qmn_array_for_variables['total_score'] >= $mlw_each[0] && $qmn_array_for_variables['total_score'] <= $mlw_each[1]) {
1243
+ $mlw_message = htmlspecialchars_decode($mlw_each[2], ENT_QUOTES);
1244
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1245
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1246
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1247
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1248
+ $mlw_headers = 'From: ' . $from_email_array["from_name"] . ' <' . $from_email_array["from_email"] . '>' . "\r\n";
1249
+ wp_mail($qmn_array_for_variables['user_email'], $mlw_each[3], $mlw_message, $mlw_headers, $attachments);
1250
+ break;
1251
+ }
1252
+ }
1253
+ }
1254
+ } else {
1255
+
1256
+ //Uses older email system still which was before different emails were created.
1257
+ $mlw_message = htmlspecialchars_decode($qmn_quiz_options->user_email_template, ENT_QUOTES);
1258
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1259
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1260
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1261
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1262
+ $mlw_headers = 'From: ' . $from_email_array["from_name"] . ' <' . $from_email_array["from_email"] . '>' . "\r\n";
1263
+ wp_mail($qmn_array_for_variables['user_email'], "Quiz Results For " . $qmn_quiz_options->quiz_name, $mlw_message, $mlw_headers, $attachments);
1264
+ }
1265
+ }
1266
+ }
1267
+ remove_filter('wp_mail_content_type', 'mlw_qmn_set_html_content_type');
1268
+ }
1269
+
1270
+ /**
1271
+ * Send Admin Email
1272
+ *
1273
+ * Prepares the email to the admin and then sends the email
1274
+ *
1275
+ * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
1276
+ * @since 4.0.0
1277
+ * @param array $qmn_quiz_options The database row of the quiz
1278
+ * @param arrar $qmn_array_for_variables The array of results for the quiz
1279
+ */
1280
+ public function send_admin_email($qmn_quiz_options, $qmn_array_for_variables) {
1281
+ //Switch email type to HTML
1282
+ add_filter('wp_mail_content_type', 'mlw_qmn_set_html_content_type');
1283
+
1284
+ $mlw_message = "";
1285
+ if ($qmn_quiz_options->send_admin_email == "0") {
1286
+ if ($qmn_quiz_options->admin_email != "") {
1287
+ $from_email_array = maybe_unserialize($qmn_quiz_options->email_from_text);
1288
+ if (!isset($from_email_array["from_email"])) {
1289
+ $from_email_array = array(
1290
+ 'from_name' => $qmn_quiz_options->email_from_text,
1291
+ 'from_email' => $qmn_quiz_options->admin_email,
1292
+ 'reply_to' => 1
1293
+ );
1294
+ }
1295
+
1296
+ if (!is_email($from_email_array["from_email"])) {
1297
+ if (is_email($qmn_quiz_options->admin_email)) {
1298
+ $from_email_array["from_email"] = $qmn_quiz_options->admin_email;
1299
+ } else {
1300
+ $from_email_array["from_email"] = get_option('admin_email ', 'test@example.com');
1301
+ }
1302
+ }
1303
+
1304
+ $mlw_message = "";
1305
+ $mlw_subject = "";
1306
+ if (is_serialized($qmn_quiz_options->admin_email_template) && is_array(@unserialize($qmn_quiz_options->admin_email_template))) {
1307
+ $mlw_admin_email_array = @unserialize($qmn_quiz_options->admin_email_template);
1308
+
1309
+ //Cycle through landing pages
1310
+ foreach ($mlw_admin_email_array as $mlw_each) {
1311
+
1312
+ //Generate Email Subject
1313
+ if (!isset($mlw_each["subject"])) {
1314
+ $mlw_each["subject"] = "Quiz Results For %QUIZ_NAME";
1315
+ }
1316
+ $mlw_each["subject"] = apply_filters('mlw_qmn_template_variable_results_page', $mlw_each["subject"], $qmn_array_for_variables);
1317
+
1318
+ //Check to see if default
1319
+ if ($mlw_each["begin_score"] == 0 && $mlw_each["end_score"] == 0) {
1320
+ $mlw_message = htmlspecialchars_decode($mlw_each["message"], ENT_QUOTES);
1321
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1322
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1323
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1324
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1325
+ $mlw_subject = $mlw_each["subject"];
1326
+ break;
1327
+ } else {
1328
+ //Check to see if points fall in correct range
1329
+ 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"]) {
1330
+ $mlw_message = htmlspecialchars_decode($mlw_each["message"], ENT_QUOTES);
1331
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1332
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1333
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1334
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1335
+ $mlw_subject = $mlw_each["subject"];
1336
+ break;
1337
+ }
1338
+
1339
+ //Check to see if score fall in correct range
1340
+ 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"]) {
1341
+ $mlw_message = htmlspecialchars_decode($mlw_each["message"], ENT_QUOTES);
1342
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1343
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1344
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1345
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1346
+ $mlw_subject = $mlw_each["subject"];
1347
+ break;
1348
+ }
1349
+ }
1350
+ }
1351
+ } else {
1352
+ $mlw_message = htmlspecialchars_decode($qmn_quiz_options->admin_email_template, ENT_QUOTES);
1353
+ $mlw_message = apply_filters('mlw_qmn_template_variable_results_page', $mlw_message, $qmn_array_for_variables);
1354
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1355
+ $mlw_message = str_replace("<br/>", "<br>", $mlw_message);
1356
+ $mlw_message = str_replace("<br />", "<br>", $mlw_message);
1357
+ $mlw_subject = "Quiz Results For " . $qmn_quiz_options->quiz_name;
1358
+ }
1359
+ }
1360
+ if (get_option('mlw_advert_shows') == 'true') {
1361
+ $mlw_message .= "<br>This email was generated by the Quiz And Survey Master plugin";
1362
+ }
1363
+ $headers = array(
1364
+ 'From: ' . $from_email_array["from_name"] . ' <' . $from_email_array["from_email"] . '>'
1365
+ );
1366
+ if ($from_email_array["reply_to"] == 0) {
1367
+ $headers[] = 'Reply-To: ' . $qmn_array_for_variables["user_name"] . " <" . $qmn_array_for_variables["user_email"] . ">";
1368
+ }
1369
+ $admin_emails = explode(",", $qmn_quiz_options->admin_email);
1370
+ foreach ($admin_emails as $admin_email) {
1371
+ if (is_email($admin_email)) {
1372
+ wp_mail($admin_email, $mlw_subject, $mlw_message, $headers);
1373
+ }
1374
+ }
1375
+ }
1376
+
1377
+ //Remove HTML type for emails
1378
+ remove_filter('wp_mail_content_type', 'mlw_qmn_set_html_content_type');
1379
+ }
1380
+
1381
+ /**
1382
+ * Returns the quiz taker's IP if IP collection is enabled
1383
+ *
1384
+ * @since 5.3.0
1385
+ * @return string The IP address or a phrase if not collected
1386
+ */
1387
+ private function get_user_ip() {
1388
+ $ip = __('Not collected', 'quiz-master-next');
1389
+ $settings = (array) get_option('qmn-settings');
1390
+ $ip_collection = '0';
1391
+ if (isset($settings['ip_collection'])) {
1392
+ $ip_collection = $settings['ip_collection'];
1393
+ }
1394
+ if ('1' != $ip_collection) {
1395
+ if ($_SERVER['REMOTE_ADDR']) {
1396
+ $ip = $_SERVER['REMOTE_ADDR'];
1397
+ } else {
1398
+ $ip = __('Unknown', 'quiz-master-next');
1399
+ }
1400
+ }
1401
+ return $ip;
1402
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1404
  }
1405
+
1406
  global $qmnQuizManager;
1407
  $qmnQuizManager = new QMNQuizManager();
1408
 
1409
  add_filter('qmn_begin_shortcode', 'qmn_require_login_check', 10, 3);
1410
+
1411
+ function qmn_require_login_check($display, $qmn_quiz_options, $qmn_array_for_variables) {
1412
+ global $qmn_allowed_visit;
1413
+ if ($qmn_quiz_options->require_log_in == 1 && !is_user_logged_in()) {
1414
+ $qmn_allowed_visit = false;
1415
+ $mlw_message = wpautop(htmlspecialchars_decode($qmn_quiz_options->require_log_in_text, ENT_QUOTES));
1416
+ $mlw_message = apply_filters('mlw_qmn_template_variable_quiz_page', $mlw_message, $qmn_array_for_variables);
1417
+ $mlw_message = str_replace("\n", "<br>", $mlw_message);
1418
+ $display .= $mlw_message;
1419
+ $display .= wp_login_form(array('echo' => false));
1420
+ }
1421
+ return $display;
 
1422
  }
1423
 
1424
+ add_filter('qmn_begin_shortcode', 'qsm_scheduled_timeframe_check', 10, 3);
1425
+
1426
+ function qsm_scheduled_timeframe_check($display, $options, $variable_data) {
1427
+ global $qmn_allowed_visit;
1428
+
1429
+ // Checks if the start and end dates have data
1430
+ if (!empty($options->scheduled_time_start) && !empty($options->scheduled_time_end)) {
1431
+ $start = strtotime($options->scheduled_time_start);
1432
+ $end = strtotime($options->scheduled_time_end) + 86399;
1433
+
1434
+ // Checks if the current timestamp is outside of scheduled timeframe
1435
+ if (current_time('timestamp') < $start || current_time('timestamp') > $end) {
1436
+ $qmn_allowed_visit = false;
1437
+ $message = wpautop(htmlspecialchars_decode($options->scheduled_timeframe_text, ENT_QUOTES));
1438
+ $message = apply_filters('mlw_qmn_template_variable_quiz_page', $message, $variable_data);
1439
+ $display .= str_replace("\n", "<br>", $message);
1440
+ }
1441
+ }
1442
+ return $display;
1443
  }
1444
 
1445
  add_filter('qmn_begin_shortcode', 'qmn_total_user_tries_check', 10, 3);
1453
  * @param array $qmn_array_for_variables The array of data by the quiz
1454
  * @return string The altered HTML display for the quiz
1455
  */
1456
+ function qmn_total_user_tries_check($display, $qmn_quiz_options, $qmn_array_for_variables) {
1457
+
1458
+ global $qmn_allowed_visit;
1459
+ if ($qmn_quiz_options->total_user_tries != 0) {
1460
+
1461
+ // Prepares the variables
1462
+ global $wpdb;
1463
+ $mlw_qmn_user_try_count = 0;
1464
+
1465
+ // Checks if the user is logged in. If so, check by user id. If not, check by IP.
1466
+ if (is_user_logged_in()) {
1467
+ $current_user = wp_get_current_user();
1468
+ $mlw_qmn_user_try_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "mlw_results WHERE user=%d AND deleted='0' AND quiz_id=%d", $current_user->ID, $qmn_array_for_variables['quiz_id']));
1469
+ } else {
1470
+ $mlw_qmn_user_try_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "mlw_results WHERE user_ip='%s' AND deleted='0' AND quiz_id=%d", $qmn_array_for_variables['user_ip'], $qmn_array_for_variables['quiz_id']));
1471
+ }
1472
+
1473
+ // If user has already reached the limit for this quiz
1474
+ if ($mlw_qmn_user_try_count >= $qmn_quiz_options->total_user_tries) {
1475
+
1476
+ // Stops the quiz and prepares entered text
1477
+ $qmn_allowed_visit = false;
1478
+ $mlw_message = wpautop(htmlspecialchars_decode($qmn_quiz_options->total_user_tries_text, ENT_QUOTES));
1479
+ $mlw_message = apply_filters('mlw_qmn_template_variable_quiz_page', $mlw_message, $qmn_array_for_variables);
1480
+ $display .= $mlw_message;
1481
+ }
1482
+ }
1483
+ return $display;
1484
  }
1485
 
1486
  add_filter('qmn_begin_quiz', 'qmn_total_tries_check', 10, 3);
1487
+
1488
+ function qmn_total_tries_check($display, $qmn_quiz_options, $qmn_array_for_variables) {
1489
+ global $qmn_allowed_visit;
1490
+ if ($qmn_quiz_options->limit_total_entries != 0) {
1491
+ global $wpdb;
1492
+ $mlw_qmn_entries_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(quiz_id) FROM " . $wpdb->prefix . "mlw_results WHERE deleted='0' AND quiz_id=%d", $qmn_array_for_variables['quiz_id']));
1493
+ if ($mlw_qmn_entries_count >= $qmn_quiz_options->limit_total_entries) {
1494
+ $mlw_message = wpautop(htmlspecialchars_decode($qmn_quiz_options->limit_total_entries_text, ENT_QUOTES));
1495
+ $mlw_message = apply_filters('mlw_qmn_template_variable_quiz_page', $mlw_message, $qmn_array_for_variables);
1496
+ $display .= $mlw_message;
1497
+ $qmn_allowed_visit = false;
1498
+ }
1499
+ }
1500
+ return $display;
 
 
1501
  }
1502
 
1503
  add_filter('qmn_begin_quiz', 'qmn_pagination_check', 10, 3);
1504
+
1505
+ function qmn_pagination_check($display, $qmn_quiz_options, $qmn_array_for_variables) {
1506
+ if ($qmn_quiz_options->pagination != 0) {
1507
+ global $wpdb;
1508
+ global $qmn_json_data;
1509
+ $total_questions = 0;
1510
+ if ($qmn_quiz_options->question_from_total != 0) {
1511
+ $total_questions = $qmn_quiz_options->question_from_total;
1512
+ } else {
1513
+ $questions = QSM_Questions::load_questions_by_pages($qmn_quiz_options->quiz_id);
1514
+ $total_questions = count($questions);
1515
+ }
1516
+ $display .= "<style>.quiz_section { display: none; }</style>";
1517
+
1518
+ $qmn_json_data["pagination"] = array(
1519
+ 'amount' => $qmn_quiz_options->pagination,
1520
+ 'section_comments' => $qmn_quiz_options->comment_section,
1521
+ 'total_questions' => $total_questions,
1522
+ 'previous_text' => $qmn_quiz_options->previous_button_text,
1523
+ 'next_text' => $qmn_quiz_options->next_button_text
1524
+ );
1525
+ }
1526
+ return $display;
1527
  }
1528
 
1529
+ add_filter('qmn_begin_quiz_form', 'qmn_timer_check', 15, 3);
1530
+
1531
+ function qmn_timer_check($display, $qmn_quiz_options, $qmn_array_for_variables) {
1532
+ global $qmn_allowed_visit;
1533
+ global $qmn_json_data;
1534
+ if ($qmn_allowed_visit && $qmn_quiz_options->timer_limit != 0) {
1535
+ $qmn_json_data["timer_limit"] = $qmn_quiz_options->timer_limit;
1536
+ $display .= '<div style="display:none;" id="mlw_qmn_timer" class="mlw_qmn_timer"></div>';
1537
+ }
1538
+ return $display;
1539
  }
1540
 
1541
  add_filter('qmn_begin_quiz', 'qmn_update_views', 10, 3);
1542
+
1543
+ function qmn_update_views($display, $qmn_quiz_options, $qmn_array_for_variables) {
1544
+ global $wpdb;
1545
+ $mlw_views = $qmn_quiz_options->quiz_views;
1546
+ $mlw_views += 1;
1547
+ $results = $wpdb->update(
1548
+ $wpdb->prefix . "mlw_quizzes", array(
1549
+ 'quiz_views' => $mlw_views
1550
+ ), array('quiz_id' => $qmn_array_for_variables["quiz_id"]), array(
1551
+ '%d'
1552
+ ), array('%d')
1553
+ );
1554
+ return $display;
 
 
 
 
1555
  }
1556
 
1557
  add_filter('qmn_begin_results', 'qmn_update_taken', 10, 3);
1558
+
1559
+ function qmn_update_taken($display, $qmn_quiz_options, $qmn_array_for_variables) {
1560
+ global $wpdb;
1561
+ $mlw_taken = $qmn_quiz_options->quiz_taken;
1562
+ $mlw_taken += 1;
1563
+ $results = $wpdb->update(
1564
+ $wpdb->prefix . "mlw_quizzes", array(
1565
+ 'quiz_taken' => $mlw_taken
1566
+ ), array('quiz_id' => $qmn_array_for_variables["quiz_id"]), array(
1567
+ '%d'
1568
+ ), array('%d')
1569
+ );
1570
+ return $display;
 
 
 
 
1571
  }
1572
 
1573
  /*
1574
+ This function helps set the email type to HTML
1575
+ */
1576
+
1577
  function mlw_qmn_set_html_content_type() {
1578
 
1579
+ return 'text/html';
1580
  }
1581
  ?>
php/classes/class-qsm-contact-manager.php CHANGED
@@ -47,6 +47,8 @@ class QSM_Contact_Manager {
47
 
48
  // Loads fields.
49
  $fields = self::load_fields();
 
 
50
 
51
  // If fields are empty and backwards-compatible fields are turned on then, use older system.
52
  if ( ( empty( $fields ) || ! is_array( $fields ) ) && ( 2 != $options->user_name || 2 != $options->user_comp || 2 != $options->user_email || 2 != $options->user_phone ) ) {
@@ -59,7 +61,7 @@ class QSM_Contact_Manager {
59
  }
60
  ?>
61
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->name_field_text, ENT_QUOTES ); ?></span>
62
- <input type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserName' value='<?php echo esc_attr( $name ); ?>' />
63
  <?php
64
  }
65
 
@@ -71,10 +73,10 @@ class QSM_Contact_Manager {
71
  }
72
  ?>
73
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->business_field_text, ENT_QUOTES ); ?></span>
74
- <input type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserComp' value='' />
75
  <?php
76
  }
77
-
78
  // Check for email field.
79
  if ( 2 != $options->user_email ) {
80
  $class = '';
@@ -83,7 +85,7 @@ class QSM_Contact_Manager {
83
  }
84
  ?>
85
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->email_field_text, ENT_QUOTES ); ?></span>
86
- <input type='email' class='mlwEmail <?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserEmail' value='<?php echo esc_attr( $email ); ?>' />
87
  <?php
88
  }
89
 
@@ -95,12 +97,12 @@ class QSM_Contact_Manager {
95
  }
96
  ?>
97
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->phone_field_text, ENT_QUOTES ); ?></span>
98
- <input type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserPhone' value='' />
99
  <?php
100
  }
101
  } elseif ( ! empty( $fields ) && is_array( $fields ) ) {
102
 
103
- // Cycle through each of the contact fields.
104
  $total_fields = count( $fields );
105
  for ( $i = 0; $i < $total_fields; $i++ ) {
106
 
@@ -124,7 +126,7 @@ class QSM_Contact_Manager {
124
  }
125
  ?>
126
  <span class='mlw_qmn_question qsm_question'><?php echo $fields[ $i ]['label']; ?></span>
127
- <input type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='contact_field_<?php echo $i; ?>' value='<?php echo esc_attr( $value ); ?>' />
128
  <?php
129
  break;
130
 
@@ -134,7 +136,7 @@ class QSM_Contact_Manager {
134
  }
135
  ?>
136
  <span class='mlw_qmn_question qsm_question'><?php echo $fields[ $i ]['label']; ?></span>
137
- <input type='text' class='mlwEmail <?php echo esc_attr( $class ); ?>' x-webkit-speech name='contact_field_<?php echo $i; ?>' value='<?php echo esc_attr( $value ); ?>' />
138
  <?php
139
  break;
140
 
47
 
48
  // Loads fields.
49
  $fields = self::load_fields();
50
+
51
+ $contact_disable_autofill = $options->contact_disable_autofill;
52
 
53
  // If fields are empty and backwards-compatible fields are turned on then, use older system.
54
  if ( ( empty( $fields ) || ! is_array( $fields ) ) && ( 2 != $options->user_name || 2 != $options->user_comp || 2 != $options->user_email || 2 != $options->user_phone ) ) {
61
  }
62
  ?>
63
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->name_field_text, ENT_QUOTES ); ?></span>
64
+ <input <?php if($contact_disable_autofill){ echo "autocomplete='off'"; } ?> type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserName' value='<?php echo esc_attr( $name ); ?>' />
65
  <?php
66
  }
67
 
73
  }
74
  ?>
75
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->business_field_text, ENT_QUOTES ); ?></span>
76
+ <input <?php if($contact_disable_autofill){ echo "autocomplete='off'"; } ?> type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserComp' value='' />
77
  <?php
78
  }
79
+
80
  // Check for email field.
81
  if ( 2 != $options->user_email ) {
82
  $class = '';
85
  }
86
  ?>
87
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->email_field_text, ENT_QUOTES ); ?></span>
88
+ <input <?php if($contact_disable_autofill){ echo "autocomplete='off'"; } ?> type='email' class='mlwEmail <?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserEmail' value='<?php echo esc_attr( $email ); ?>' />
89
  <?php
90
  }
91
 
97
  }
98
  ?>
99
  <span class='mlw_qmn_question qsm_question'><?php echo htmlspecialchars_decode( $options->phone_field_text, ENT_QUOTES ); ?></span>
100
+ <input <?php if($contact_disable_autofill){ echo "autocomplete='off'"; } ?> type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='mlwUserPhone' value='' />
101
  <?php
102
  }
103
  } elseif ( ! empty( $fields ) && is_array( $fields ) ) {
104
 
105
+ // Cycle through each of the contact fields.
106
  $total_fields = count( $fields );
107
  for ( $i = 0; $i < $total_fields; $i++ ) {
108
 
126
  }
127
  ?>
128
  <span class='mlw_qmn_question qsm_question'><?php echo $fields[ $i ]['label']; ?></span>
129
+ <input <?php if($contact_disable_autofill){ echo "autocomplete='off'"; } ?> type='text' class='<?php echo esc_attr( $class ); ?>' x-webkit-speech name='contact_field_<?php echo $i; ?>' value='<?php echo esc_attr( $value ); ?>' />
130
  <?php
131
  break;
132
 
136
  }
137
  ?>
138
  <span class='mlw_qmn_question qsm_question'><?php echo $fields[ $i ]['label']; ?></span>
139
+ <input <?php if($contact_disable_autofill){ echo "autocomplete='off'"; } ?> type='text' class='mlwEmail <?php echo esc_attr( $class ); ?>' x-webkit-speech name='contact_field_<?php echo $i; ?>' value='<?php echo esc_attr( $value ); ?>' />
140
  <?php
141
  break;
142
 
php/classes/class-qsm-install.php CHANGED
@@ -455,6 +455,25 @@ class QSM_Install {
455
  'default' => 2
456
  );
457
  $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
458
 
459
  // Registers message_before setting
460
  $field_array = array(
455
  'default' => 2
456
  );
457
  $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' );
458
+
459
+ // Registers hide_auto fill setting
460
+ $field_array = array(
461
+ 'id' => 'contact_disable_autofill',
462
+ 'label' => __('Disable auto fill for contact input?', 'quiz-master-next'),
463
+ 'type' => 'radio',
464
+ 'options' => array(
465
+ array(
466
+ 'label' => __('No', 'quiz-master-next'),
467
+ 'value' => 0
468
+ ),
469
+ array(
470
+ 'label' => __('Yes', 'quiz-master-next'),
471
+ 'value' => 1
472
+ )
473
+ ),
474
+ 'default' => 0
475
+ );
476
+ $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' );
477
 
478
  // Registers message_before setting
479
  $field_array = array(
php/question-types.php CHANGED
@@ -301,9 +301,11 @@ function qmn_small_open_display($id, $question, $answers)
301
  $question_display = '';
302
  global $mlwQuizMasterNext;
303
  $required = $mlwQuizMasterNext->pluginHelper->get_question_setting($id, 'required');
304
- if ($required == 0) {$mlw_requireClass = "mlwRequiredText";} else {$mlw_requireClass = "";}
 
 
305
  $question_display .= "<span class='mlw_qmn_question'>".do_shortcode(htmlspecialchars_decode($question, ENT_QUOTES))."</span>";
306
- $question_display .= "<input type='text' class='mlw_answer_open_text $mlw_requireClass' name='question".$id."' />";
307
  return $question_display;
308
  }
309
 
@@ -886,8 +888,10 @@ function qmn_fill_blank_display($id, $question, $answers)
886
  $question_display = '';
887
  global $mlwQuizMasterNext;
888
  $required = $mlwQuizMasterNext->pluginHelper->get_question_setting($id, 'required');
 
 
889
  if ($required == 0) {$mlw_requireClass = "mlwRequiredText";} else {$mlw_requireClass = "";}
890
- $input_text = "<input type='text' class='qmn_fill_blank $mlw_requireClass' name='question".$id."' />";
891
  if (strpos($question, '%BLANK%') !== false)
892
  {
893
  $question = str_replace( "%BLANK%", $input_text, do_shortcode(htmlspecialchars_decode($question, ENT_QUOTES)));
301
  $question_display = '';
302
  global $mlwQuizMasterNext;
303
  $required = $mlwQuizMasterNext->pluginHelper->get_question_setting($id, 'required');
304
+ $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting($id, 'autofill');
305
+ $autofill_att = $autofill ? "autocomplete='off'" : '';
306
+ if ($required == 0) {$mlw_requireClass = "mlwRequiredText";} else {$mlw_requireClass = "";}
307
  $question_display .= "<span class='mlw_qmn_question'>".do_shortcode(htmlspecialchars_decode($question, ENT_QUOTES))."</span>";
308
+ $question_display .= "<input ". $autofill_att ." type='text' class='mlw_answer_open_text $mlw_requireClass' name='question".$id."' />";
309
  return $question_display;
310
  }
311
 
888
  $question_display = '';
889
  global $mlwQuizMasterNext;
890
  $required = $mlwQuizMasterNext->pluginHelper->get_question_setting($id, 'required');
891
+ $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting($id, 'autofill');
892
+ $autofill_att = $autofill ? "autocomplete='off'" : '';
893
  if ($required == 0) {$mlw_requireClass = "mlwRequiredText";} else {$mlw_requireClass = "";}
894
+ $input_text = "<input ". $autofill_att ." type='text' class='qmn_fill_blank $mlw_requireClass' name='question".$id."' />";
895
  if (strpos($question, '%BLANK%') !== false)
896
  {
897
  $question = str_replace( "%BLANK%", $input_text, do_shortcode(htmlspecialchars_decode($question, ENT_QUOTES)));
php/rest-api.php CHANGED
@@ -225,6 +225,7 @@ function qsm_rest_get_questions( WP_REST_Request $request ) {
225
  'answers' => $question['answers'],
226
  'page' => $question['page'],
227
  'answerEditor' => $question['settings']['answerEditor'],
 
228
  );
229
  }
230
  return $question_array;
@@ -316,7 +317,8 @@ function qsm_rest_save_question( WP_REST_Request $request ) {
316
  );
317
  $settings = array(
318
  'required' => $request['required'],
319
- 'answerEditor' => $request['answer_editor']
 
320
  );
321
  $intial_answers = $request['answers'];
322
  $answers = array();
225
  'answers' => $question['answers'],
226
  'page' => $question['page'],
227
  'answerEditor' => $question['settings']['answerEditor'],
228
+ 'autofill' => $question['settings']['autofill'],
229
  );
230
  }
231
  return $question_array;
317
  );
318
  $settings = array(
319
  'required' => $request['required'],
320
+ 'answerEditor' => $request['answer_editor'],
321
+ 'autofill' => $request['autofill']
322
  );
323
  $intial_answers = $request['answers'];
324
  $answers = array();
php/template-variables.php CHANGED
@@ -57,11 +57,65 @@ add_filter('mlw_qmn_template_variable_results_page', 'mlw_qmn_variable_date',10,
57
  add_filter('mlw_qmn_template_variable_results_page', 'mlw_qmn_variable_date_taken',10,2);
58
  add_filter('mlw_qmn_template_variable_results_page', 'qsm_variable_facebook_share',10,2);
59
  add_filter('mlw_qmn_template_variable_results_page', 'qsm_variable_twitter_share',10,2);
 
60
 
61
  add_filter('mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_quiz_name',10,2);
62
  add_filter('mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_date',10,2);
63
  add_filter('mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_current_user',10,2);
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  * Adds Facebook sharing link using the %FACEBOOK_SHARE% variable
67
  */
57
  add_filter('mlw_qmn_template_variable_results_page', 'mlw_qmn_variable_date_taken',10,2);
58
  add_filter('mlw_qmn_template_variable_results_page', 'qsm_variable_facebook_share',10,2);
59
  add_filter('mlw_qmn_template_variable_results_page', 'qsm_variable_twitter_share',10,2);
60
+ add_filter('mlw_qmn_template_variable_results_page', 'qsm_variable_poll_result',10,2);
61
 
62
  add_filter('mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_quiz_name',10,2);
63
  add_filter('mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_date',10,2);
64
  add_filter('mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_current_user',10,2);
65
 
66
+ /**
67
+ * Show poll result
68
+ * @param str $content
69
+ * @param arr $mlw_quiz_array
70
+ */
71
+ function qsm_variable_poll_result($content, $mlw_quiz_array){
72
+ while ( false !== strpos($content, '%POLL_RESULTS_') ) {
73
+ $question_id = mlw_qmn_get_string_between($content, '%POLL_RESULTS_', '%');
74
+ $quiz_id = $mlw_quiz_array['quiz_id'];
75
+ global $wpdb;
76
+ $table_name = $wpdb->prefix . 'mlw_results';
77
+ $table_question = $wpdb->prefix . 'mlw_questions';
78
+ $total_query = $wpdb->get_row('SELECT count(*) AS total_count FROM ' . $table_name . ' WHERE quiz_id = ' . $quiz_id,ARRAY_A);
79
+ $total_result = $total_query['total_count'];
80
+ $ser_answer = $wpdb->get_row('SELECT answer_array FROM ' . $table_question . ' WHERE question_id = ' . $question_id,ARRAY_A);
81
+ $ser_answer_arry = unserialize($ser_answer['answer_array']);
82
+ $total_quiz_results = $wpdb->get_results('SELECT quiz_results FROM ' . $table_name . ' WHERE quiz_id = ' . $quiz_id,ARRAY_A);
83
+ $answer_array = array();
84
+ if($total_quiz_results){
85
+ foreach ($total_quiz_results as $key => $value) {
86
+ $userdb = unserialize($value['quiz_results']);
87
+ if(!empty($userdb)){
88
+ $key = array_search($question_id, array_column($userdb[1], 'id'));
89
+ $answer_array[] = isset($userdb[1][$key]) ? $userdb[1][$key][1] : '';
90
+ }
91
+ }
92
+ }
93
+ $vals = array_count_values($answer_array);
94
+ $str = '';
95
+ if($vals){
96
+ $str .= '<h4>Poll Result:</h4>';
97
+ foreach ($vals as $answer_str => $answer_count) {
98
+ if($answer_str != ''){
99
+ $percentage = number_format($answer_count / $total_result * 100,2) ;
100
+ $str .= $answer_str . ' : ' . $percentage .'%<br/>';
101
+ $str .= '<progress value="'. $percentage .'" max="100">'. $percentage .' %</progress><br/>';
102
+ }
103
+ }
104
+ }
105
+ $content = str_replace( "%POLL_RESULTS_". $question_id ."%" , $str, $content);
106
+ }
107
+ return $content;
108
+ }
109
+
110
+ function mlw_qmn_get_string_between($string, $start, $end){
111
+ $string = ' ' . $string;
112
+ $ini = strpos($string, $start);
113
+ if ($ini == 0) return '';
114
+ $ini += strlen($start);
115
+ $len = strpos($string, $end, $ini) - $ini;
116
+ return substr($string, $ini, $len);
117
+ }
118
+
119
  /**
120
  * Adds Facebook sharing link using the %FACEBOOK_SHARE% variable
121
  */
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: quizsurvey
3
  Tags: quiz, survey, lead, test, score, exam, questionnaire, question
4
  Requires at least: 4.9
5
- Tested up to: 5.1.1
6
  Requires PHP: 5.4
7
- Stable tag: 6.3.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -111,6 +111,16 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
111
 
112
  == Changelog ==
113
 
 
 
 
 
 
 
 
 
 
 
114
  = 6.3.0 (April 20, 2019) =
115
  * Massive UI update
116
  * Closed Enhancement: Support for Image and Rich answers
2
  Contributors: quizsurvey
3
  Tags: quiz, survey, lead, test, score, exam, questionnaire, question
4
  Requires at least: 4.9
5
+ Tested up to: 5.2
6
  Requires PHP: 5.4
7
+ Stable tag: 6.3.1
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
111
 
112
  == Changelog ==
113
 
114
+ = 6.3.1 (May 19, 2019) =
115
+ * Closed Bug: Duplicate post issue ([Issue #758](https://github.com/QuizandSurveyMaster/quiz_master_next/issues/758))
116
+ * Closed Enhancement: Option to turn off autofill ([WP Issue](https://wordpress.org/support/topic/can-you-add-an-option-to-turn-off-autofill-on-galaxy-phones-and-other-devices/))
117
+ * Added Feature: Preview quiz within the quiz edit page.
118
+ * Added Feature: Auto save quiz and questions
119
+ * Closed Enhancement: Disable autofill for contact fields ([Issue #718](https://github.com/QuizandSurveyMaster/quiz_master_next/issues/718))
120
+ * Closed Enhancement: Added %POLL_RESULTS_X% tag for results page to show poll results ([Issue #458](https://github.com/QuizandSurveyMaster/quiz_master_next/issues/458))
121
+ * Closed Bug: Facebook Share not working properly ([WP Issue](https://wordpress.org/support/topic/facebook-share-40/))
122
+
123
+
124
  = 6.3.0 (April 20, 2019) =
125
  * Massive UI update
126
  * Closed Enhancement: Support for Image and Rich answers