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

Version Description

(December 25, 2017) = * Closed Bug: Timezone ID '' is invalid - (Issue #606) * Closed Bug: Required contact fields not working correctly when the loggedin_user_contact option is set to no - (Issue #603)

Download this release

Release Info

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

Code changes from version 5.1.5 to 5.1.6

mlw_quizmaster2.php CHANGED
@@ -1,26 +1,27 @@
1
  <?php
2
  /**
3
- * Plugin Name: Quiz And Survey Master
4
- * Description: Easily and quickly add quizzes and surveys to your website.
5
- * Version: 5.1.5
6
- * Author: Frank Corso
7
- * Author URI: https://www.quizandsurveymaster.com/
8
- * Plugin URI: https://www.quizandsurveymaster.com/
9
- * Text Domain: quiz-master-next
10
- *
11
- * @author Frank Corso
12
- * @version 5.1.5
13
- */
 
14
  if ( ! defined( 'ABSPATH' ) ) exit;
15
 
16
  define( 'QSM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
17
  /**
18
- * This class is the main class of the plugin
19
- *
20
- * When loaded, it loads the included plugin files and add functions to hooks or filters. The class also handles the admin menu
21
- *
22
- * @since 3.6.1
23
- */
24
  class MLWQuizMasterNext {
25
 
26
  /**
@@ -29,7 +30,7 @@ class MLWQuizMasterNext {
29
  * @var string
30
  * @since 4.0.0
31
  */
32
- public $version = '5.1.5';
33
 
34
  /**
35
  * QSM Alert Manager Object
1
  <?php
2
  /**
3
+ * Plugin Name: Quiz And Survey Master
4
+ * Description: Easily and quickly add quizzes and surveys to your website.
5
+ * Version: 5.1.6
6
+ * Author: Frank Corso
7
+ * Author URI: https://www.quizandsurveymaster.com/
8
+ * Plugin URI: https://www.quizandsurveymaster.com/
9
+ * Text Domain: quiz-master-next
10
+ *
11
+ * @author Frank Corso
12
+ * @version 5.1.6
13
+ */
14
+
15
  if ( ! defined( 'ABSPATH' ) ) exit;
16
 
17
  define( 'QSM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
18
  /**
19
+ * This class is the main class of the plugin
20
+ *
21
+ * When loaded, it loads the included plugin files and add functions to hooks or filters. The class also handles the admin menu
22
+ *
23
+ * @since 3.6.1
24
+ */
25
  class MLWQuizMasterNext {
26
 
27
  /**
30
  * @var string
31
  * @since 4.0.0
32
  */
33
+ public $version = '5.1.6';
34
 
35
  /**
36
  * QSM Alert Manager Object
php/about-page.php CHANGED
@@ -2,11 +2,11 @@
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
  /**
5
- * This function shows the about page. It also shows the changelog information.
6
- *
7
- * @return void
8
- * @since 4.4.0
9
- */
10
  function mlw_generate_about_page() {
11
 
12
  global $mlwQuizMasterNext;
@@ -16,20 +16,20 @@ function mlw_generate_about_page() {
16
  ?>
17
  <style>
18
  div.qsm_icon_wrap {
19
- background: <?php echo 'url("'.plugins_url( '../assets/icon-128x128.png' , __FILE__ ).'")'; ?> no-repeat;
20
  }
21
  </style>
22
  <div class="wrap about-wrap">
23
- <h1><?php _e('Welcome To Quiz And Survey Master (Formerly Quiz Master Next)', 'quiz-master-next'); ?></h1>
24
- <div class="about-text"><?php _e('Thank you for updating!', 'quiz-master-next'); ?></div>
25
  <div class="qsm_icon_wrap"><?php echo $version; ?></div>
26
  <h2 class="nav-tab-wrapper">
27
  <a href="#" data-tab='1' class="nav-tab nav-tab-active qsm-tab">
28
- <?php _e("What's New!", 'quiz-master-next'); ?></a>
29
  <a href="#" data-tab='2' class="nav-tab qsm-tab">
30
- <?php _e('Changelog', 'quiz-master-next'); ?></a>
31
  <a href="#" data-tab='3' class="nav-tab qsm-tab">
32
- <?php _e('People Who Make QSM Possible', 'quiz-master-next'); ?></a>
33
  </h2>
34
  <div class="qsm-tab-content tab-1">
35
  <div class="feature">
@@ -54,6 +54,7 @@ function mlw_generate_about_page() {
54
  </div>
55
  <div class="qsm-tab-content tab-2" style="display: none;">
56
  <h2>Changelog</h2>
 
57
  <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 44 ); ?>
58
  <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 43 ); ?>
59
  <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 41 ); ?>
@@ -79,7 +80,8 @@ function mlw_generate_about_page() {
79
  $contributor_list .= '<li class="wp-person">';
80
  $contributor_list .= sprintf( '<a href="%s" title="%s">',
81
  esc_url( 'https://github.com/' . $contributor->login ),
82
- esc_html( sprintf( __( 'View %s', 'edd' ), $contributor->login ) )
 
83
  );
84
  $contributor_list .= sprintf( '<img src="%s" width="64" height="64" class="gravatar" alt="%s" />', esc_url( $contributor->avatar_url ), esc_html( $contributor->login ) );
85
  $contributor_list .= '</a>';
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
  /**
5
+ * This function shows the about page. It also shows the changelog information.
6
+ *
7
+ * @return void
8
+ * @since 4.4.0
9
+ */
10
  function mlw_generate_about_page() {
11
 
12
  global $mlwQuizMasterNext;
16
  ?>
17
  <style>
18
  div.qsm_icon_wrap {
19
+ background: <?php echo 'url("' . plugins_url( '../assets/icon-128x128.png', __FILE__ ) . '" )'; ?> no-repeat;
20
  }
21
  </style>
22
  <div class="wrap about-wrap">
23
+ <h1><?php _e( 'Welcome To Quiz And Survey Master (Formerly Quiz Master Next)', 'quiz-master-next' ); ?></h1>
24
+ <div class="about-text"><?php _e( 'Thank you for updating!', 'quiz-master-next' ); ?></div>
25
  <div class="qsm_icon_wrap"><?php echo $version; ?></div>
26
  <h2 class="nav-tab-wrapper">
27
  <a href="#" data-tab='1' class="nav-tab nav-tab-active qsm-tab">
28
+ <?php _e( "What's New!", 'quiz-master-next' ); ?></a>
29
  <a href="#" data-tab='2' class="nav-tab qsm-tab">
30
+ <?php _e( 'Changelog', 'quiz-master-next' ); ?></a>
31
  <a href="#" data-tab='3' class="nav-tab qsm-tab">
32
+ <?php _e( 'People Who Make QSM Possible', 'quiz-master-next' ); ?></a>
33
  </h2>
34
  <div class="qsm-tab-content tab-1">
35
  <div class="feature">
54
  </div>
55
  <div class="qsm-tab-content tab-2" style="display: none;">
56
  <h2>Changelog</h2>
57
+ <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 45 ); ?>
58
  <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 44 ); ?>
59
  <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 43 ); ?>
60
  <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 41 ); ?>
80
  $contributor_list .= '<li class="wp-person">';
81
  $contributor_list .= sprintf( '<a href="%s" title="%s">',
82
  esc_url( 'https://github.com/' . $contributor->login ),
83
+ // translators: This is the 'title' attribute for GitHub contributors. This would add the GitHub user such as 'View fpcorso'.
84
+ esc_html( sprintf( __( 'View %s', 'quiz-master-next' ), $contributor->login ) )
85
  );
86
  $contributor_list .= sprintf( '<img src="%s" width="64" height="64" class="gravatar" alt="%s" />', esc_url( $contributor->avatar_url ), esc_html( $contributor->login ) );
87
  $contributor_list .= '</a>';
php/class-qmn-quiz-manager.php CHANGED
@@ -1,34 +1,38 @@
1
  <?php
 
 
 
 
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
  /**
5
- * This class generates the contents of the quiz shortcode
6
- *
7
- * @since 4.0.0
8
- */
9
  class QMNQuizManager {
10
 
11
  /**
12
- * Main Construct Function
13
- *
14
- * Call functions within class
15
- *
16
- * @since 4.0.0
17
- * @uses QMNQuizManager::add_hooks() Adds actions to hooks and filters
18
- * @return void
19
- */
20
  public function __construct() {
21
  $this->add_hooks();
22
  }
23
 
24
  /**
25
- * Add Hooks
26
- *
27
- * Adds functions to relavent hooks and filters
28
- *
29
- * @since 4.0.0
30
- * @return void
31
- */
32
  public function add_hooks() {
33
  add_shortcode( 'mlw_quizmaster', array( $this, 'display_shortcode' ) );
34
  add_shortcode( 'qsm', array( $this, 'display_shortcode' ) );
@@ -42,6 +46,7 @@ class QMNQuizManager {
42
  * Generates the content for the [mlw_quizmaster] shortcode
43
  *
44
  * @since 4.0.0
 
45
  * @uses QMNQuizManager:load_questions() Loads questions
46
  * @uses QMNQuizManager:create_answer_array() Prepares answers
47
  * @uses QMNQuizManager:display_quiz() Generates and prepares quiz page
@@ -65,44 +70,38 @@ class QMNQuizManager {
65
  $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
66
  $question_amount = intval( $question_amount );
67
 
68
- //Legacy variable
69
  global $mlw_qmn_quiz;
70
  $mlw_qmn_quiz = $quiz;
71
 
72
- if ( ! get_option( 'timezone_string' ) ) {
73
- date_default_timezone_set( get_option( 'timezone_string' ) );
74
- }
75
  $return_display = '';
76
  $qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
77
 
78
- //If quiz options isn't found, stop function
79
- if ( is_null( $qmn_quiz_options ) || $qmn_quiz_options->quiz_name == '' ) {
80
- return __("It appears that this quiz is not set up correctly", 'quiz-master-next');
81
  }
82
 
83
- // Loads Quiz Template
84
- if ($qmn_quiz_options->theme_selected == "default")
85
- {
86
- echo "<style type='text/css'>".$qmn_quiz_options->quiz_stye."</style>";
87
- wp_enqueue_style( 'qmn_quiz_style', plugins_url( '../css/qmn_quiz.css' , __FILE__ ) );
88
- }
89
- else
90
- {
91
- $registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates($qmn_quiz_options->theme_selected);
92
  // Check direct file first, then check templates folder in plugin, then check templates file in theme.
93
- // If all fails, then load custom styling instead
94
  if ( $registered_template && file_exists( $registered_template["path"] ) ) {
95
  wp_enqueue_style( 'qmn_quiz_template', $registered_template["path"], array(), $mlwQuizMasterNext->version );
96
- } elseif ( $registered_template && file_exists( plugin_dir_path(__FILE__).'../templates/'.$registered_template["path"] ) ) {
97
  wp_enqueue_style( 'qmn_quiz_template', plugins_url( '../templates/'.$registered_template["path"], __FILE__ ), array(), $mlwQuizMasterNext->version );
98
  } elseif ( $registered_template && file_exists( get_stylesheet_directory_uri().'/templates/'.$registered_template["path"] ) ) {
99
  wp_enqueue_style( 'qmn_quiz_template', get_stylesheet_directory_uri().'/templates/'.$registered_template["path"], array(), $mlwQuizMasterNext->version );
100
  } else {
101
- echo "<style type='text/css'>".$qmn_quiz_options->quiz_stye."</style>";
102
  }
103
  }
104
 
105
- //Start to prepare variable array for filters
106
  $qmn_array_for_variables = array(
107
  'quiz_id' => $qmn_quiz_options->quiz_id,
108
  'quiz_name' => $qmn_quiz_options->quiz_name,
@@ -127,98 +126,91 @@ class QMNQuizManager {
127
  'ajax_show_correct' => $qmn_quiz_options->ajax_show_correct
128
  );
129
 
130
- $return_display = apply_filters('qmn_begin_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables);
131
 
132
- //Check if we should be showing quiz or results page
133
- if ($qmn_allowed_visit && !isset($_POST["complete_quiz"]) && $qmn_quiz_options->quiz_name != '')
134
- {
135
  $qmn_quiz_questions = $this->load_questions( $quiz, $qmn_quiz_options, true, $question_amount );
136
- $qmn_quiz_answers = $this->create_answer_array($qmn_quiz_questions);
137
- $return_display .= $this->display_quiz($qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers, $qmn_array_for_variables);
138
- }
139
- elseif (isset($_POST["complete_quiz"]) && $_POST["complete_quiz"] == "confirmation" && $_POST["qmn_quiz_id"] == $qmn_array_for_variables["quiz_id"] )
140
- {
141
- $qmn_quiz_questions = $this->load_questions($quiz, $qmn_quiz_options, false);
142
- $qmn_quiz_answers = $this->create_answer_array($qmn_quiz_questions);
143
- $return_display .= $this->display_results($qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers, $qmn_array_for_variables);
144
- }
145
- else
146
- {
147
- //return $return_display;
148
  }
149
 
150
  $qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables );
151
 
152
  $return_display .= '<script>
153
- window.qmn_quiz_data["'.$qmn_json_data["quiz_id"].'"] = '.json_encode( $qmn_json_data ).'
154
  </script>';
155
 
156
  $return_display .= ob_get_clean();
157
- $return_display = apply_filters('qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables);
158
  return $return_display;
159
  }
160
 
161
  /**
162
- * Loads Questions
163
- *
164
- * Retrieves the questions from the database
165
- *
166
- * @since 4.0.0
167
- * @param int $quiz_id The id for the quiz
168
- * @param array $quiz_options The database row for the quiz
169
- * @param bool $is_quiz_page If the page being loaded is the quiz page or not
170
- * @param int $question_amount The amount of questions entered using the shortcode attribute
171
- * @return array The questions for the quiz
172
- */
173
  public function load_questions( $quiz_id, $quiz_options, $is_quiz_page, $question_amount = 0 ) {
174
 
175
- // Prepare variables
176
  global $wpdb;
177
- $order_by_sql = "ORDER BY question_order ASC";
178
  $limit_sql = '';
179
 
180
- // Checks if the questions should be randomized
181
- if ( $quiz_options->randomness_order == 1 || $quiz_options->randomness_order == 2 ) {
182
- $order_by_sql = "ORDER BY rand()";
183
  }
184
 
185
- // Check if we should load all questions or only a selcted amount
186
- if ($is_quiz_page && ( $quiz_options->question_from_total != 0 || $question_amount !== 0 ) ) {
187
- if ( $question_amount !== 0 ) {
188
  $limit_sql = " LIMIT $question_amount";
189
  } else {
190
- $limit_sql = " LIMIT " . intval( $quiz_options->question_from_total );
191
  }
192
  }
193
 
194
- // Returns an array of all the loaded questions
195
  return $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 ) );
196
  }
197
 
198
  /**
199
- * Prepares Answers
200
- *
201
- * Prepares or creates the answer array for the quiz
202
- *
203
- * @since 4.0.0
204
- * @param array $questions The questions for the quiz
205
- * @return array The answers for the quiz
206
- */
207
- public function create_answer_array($questions, $is_ajax = false)
208
- {
209
- //Load and prepare answer arrays
 
210
  $mlw_qmn_answer_arrays = array();
211
  $question_list = array();
212
- foreach($questions as $mlw_question_info) {
213
- $question_list[$mlw_question_info->question_id] = get_object_vars($mlw_question_info);
214
- if (is_serialized($mlw_question_info->answer_array) && is_array(@unserialize($mlw_question_info->answer_array)))
215
- {
216
- $mlw_qmn_answer_array_each = @unserialize($mlw_question_info->answer_array);
217
- $mlw_qmn_answer_arrays[$mlw_question_info->question_id] = $mlw_qmn_answer_array_each;
218
- $question_list[$mlw_question_info->question_id]["answers"] = $mlw_qmn_answer_array_each;
219
- }
220
- else
221
- {
222
  $mlw_answer_array_correct = array(0, 0, 0, 0, 0, 0);
223
  $mlw_answer_array_correct[$mlw_question_info->correct_answer-1] = 1;
224
  $mlw_qmn_answer_arrays[$mlw_question_info->question_id] = array(
@@ -239,21 +231,21 @@ class QMNQuizManager {
239
  }
240
 
241
  /**
242
- * Generates Content Quiz Page
243
- *
244
- * Generates the content for the quiz page part of the shortcode
245
- *
246
- * @since 4.0.0
247
- * @param array $qmn_quiz_options The database row of the quiz
248
- * @param array $qmn_quiz_questions The questions of the quiz
249
- * @param array $qmn_quiz_answers The answers of the quiz
250
- * @param array $qmn_array_for_variables The array of results for the quiz
251
- * @uses QMNQuizManager:display_begin_section() Creates display for beginning section
252
- * @uses QMNQuizManager:display_questions() Creates display for questions
253
- * @uses QMNQuizManager:display_comment_section() Creates display for comment section
254
- * @uses QMNQuizManager:display_end_section() Creates display for end section
255
- * @return string The content for the quiz page section
256
- */
257
  public function display_quiz( $qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers, $qmn_array_for_variables ) {
258
 
259
  global $qmn_allowed_visit;
@@ -277,7 +269,7 @@ class QMNQuizManager {
277
  'empty' => $qmn_quiz_options->empty_error_text
278
  );
279
 
280
- wp_enqueue_script( 'qmn_quiz', plugins_url( '../js/qmn_quiz.js' , __FILE__ ), array( 'jquery', 'jquery-ui-tooltip' ), $mlwQuizMasterNext->version );
281
  wp_localize_script( 'qmn_quiz', 'qmn_ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl
282
  wp_enqueue_script( 'math_jax', '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML' );
283
 
@@ -564,7 +556,7 @@ class QMNQuizManager {
564
  $mlw_qmn_timer = isset($_POST["timer"]) ? intval( $_POST["timer"] ) : 0;
565
  $qmn_array_for_variables['user_id'] = get_current_user_id();
566
  $qmn_array_for_variables['timer'] = $mlw_qmn_timer;
567
- $qmn_array_for_variables['time_taken'] = date("h:i:s A m/d/Y", current_time( 'timestamp' ) );
568
  $qmn_array_for_variables['contact'] = $contact_responses;
569
 
570
  if ( !isset( $_POST["mlw_code_captcha"] ) || ( isset( $_POST["mlw_code_captcha"] ) && $_POST["mlw_user_captcha"] == $_POST["mlw_code_captcha"] ) ) {
1
  <?php
2
+ /**
3
+ * File for the QMNQuizManager class
4
+ */
5
+
6
  if ( ! defined( 'ABSPATH' ) ) exit;
7
 
8
  /**
9
+ * This class generates the contents of the quiz shortcode
10
+ *
11
+ * @since 4.0.0
12
+ */
13
  class QMNQuizManager {
14
 
15
  /**
16
+ * Main Construct Function
17
+ *
18
+ * Call functions within class
19
+ *
20
+ * @since 4.0.0
21
+ * @uses QMNQuizManager::add_hooks() Adds actions to hooks and filters
22
+ * @return void
23
+ */
24
  public function __construct() {
25
  $this->add_hooks();
26
  }
27
 
28
  /**
29
+ * Add Hooks
30
+ *
31
+ * Adds functions to relavent hooks and filters
32
+ *
33
+ * @since 4.0.0
34
+ * @return void
35
+ */
36
  public function add_hooks() {
37
  add_shortcode( 'mlw_quizmaster', array( $this, 'display_shortcode' ) );
38
  add_shortcode( 'qsm', array( $this, 'display_shortcode' ) );
46
  * Generates the content for the [mlw_quizmaster] shortcode
47
  *
48
  * @since 4.0.0
49
+ * @param array $atts The attributes passed from the shortcode
50
  * @uses QMNQuizManager:load_questions() Loads questions
51
  * @uses QMNQuizManager:create_answer_array() Prepares answers
52
  * @uses QMNQuizManager:display_quiz() Generates and prepares quiz page
70
  $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
71
  $question_amount = intval( $question_amount );
72
 
73
+ // Legacy variable.
74
  global $mlw_qmn_quiz;
75
  $mlw_qmn_quiz = $quiz;
76
 
 
 
 
77
  $return_display = '';
78
  $qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
79
 
80
+ // If quiz options isn't found, stop function.
81
+ if ( is_null( $qmn_quiz_options ) || empty( $qmn_quiz_options->quiz_name ) ) {
82
+ return __( 'It appears that this quiz is not set up correctly', 'quiz-master-next' );
83
  }
84
 
85
+ // Loads Quiz Template.
86
+ if ( 'default' == $qmn_quiz_options->theme_selected ) {
87
+ $return_display .= '<style type="text/css">' . $qmn_quiz_options->quiz_stye . '</style>';
88
+ wp_enqueue_style( 'qmn_quiz_style', plugins_url( '../css/qmn_quiz.css', __FILE__ ) );
89
+ } else {
90
+ $registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates( $qmn_quiz_options->theme_selected );
 
 
 
91
  // Check direct file first, then check templates folder in plugin, then check templates file in theme.
92
+ // If all fails, then load custom styling instead.
93
  if ( $registered_template && file_exists( $registered_template["path"] ) ) {
94
  wp_enqueue_style( 'qmn_quiz_template', $registered_template["path"], array(), $mlwQuizMasterNext->version );
95
+ } elseif ( $registered_template && file_exists( plugin_dir_path( __FILE__ ).'../templates/'.$registered_template["path"] ) ) {
96
  wp_enqueue_style( 'qmn_quiz_template', plugins_url( '../templates/'.$registered_template["path"], __FILE__ ), array(), $mlwQuizMasterNext->version );
97
  } elseif ( $registered_template && file_exists( get_stylesheet_directory_uri().'/templates/'.$registered_template["path"] ) ) {
98
  wp_enqueue_style( 'qmn_quiz_template', get_stylesheet_directory_uri().'/templates/'.$registered_template["path"], array(), $mlwQuizMasterNext->version );
99
  } else {
100
+ echo "<style type='text/css'>" . $qmn_quiz_options->quiz_stye . "</style>";
101
  }
102
  }
103
 
104
+ // Start to prepare variable array for filters.
105
  $qmn_array_for_variables = array(
106
  'quiz_id' => $qmn_quiz_options->quiz_id,
107
  'quiz_name' => $qmn_quiz_options->quiz_name,
126
  'ajax_show_correct' => $qmn_quiz_options->ajax_show_correct
127
  );
128
 
129
+ $return_display = apply_filters( 'qmn_begin_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables );
130
 
131
+ // Check if we should be showing quiz or results page.
132
+ if ( $qmn_allowed_visit && ! isset( $_POST["complete_quiz"] ) && ! empty( $qmn_quiz_options->quiz_name ) ) {
 
133
  $qmn_quiz_questions = $this->load_questions( $quiz, $qmn_quiz_options, true, $question_amount );
134
+ $qmn_quiz_answers = $this->create_answer_array( $qmn_quiz_questions );
135
+ $return_display .= $this->display_quiz( $qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers, $qmn_array_for_variables );
136
+ } elseif ( isset( $_POST["complete_quiz"] ) && 'confirmation' == $_POST["complete_quiz"] && $_POST["qmn_quiz_id"] == $qmn_array_for_variables["quiz_id"] ) {
137
+ $qmn_quiz_questions = $this->load_questions( $quiz, $qmn_quiz_options, false );
138
+ $qmn_quiz_answers = $this->create_answer_array( $qmn_quiz_questions );
139
+ $return_display .= $this->display_results( $qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers, $qmn_array_for_variables );
140
+ } else {
141
+ // @todo Do something else here
 
 
 
 
142
  }
143
 
144
  $qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables );
145
 
146
  $return_display .= '<script>
147
+ window.qmn_quiz_data["' . $qmn_json_data["quiz_id"] . '"] = ' . json_encode( $qmn_json_data ) . '
148
  </script>';
149
 
150
  $return_display .= ob_get_clean();
151
+ $return_display = apply_filters( 'qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables );
152
  return $return_display;
153
  }
154
 
155
  /**
156
+ * Loads Questions
157
+ *
158
+ * Retrieves the questions from the database
159
+ *
160
+ * @since 4.0.0
161
+ * @param int $quiz_id The id for the quiz.
162
+ * @param array $quiz_options The database row for the quiz.
163
+ * @param bool $is_quiz_page If the page being loaded is the quiz page or not.
164
+ * @param int $question_amount The amount of questions entered using the shortcode attribute.
165
+ * @return array The questions for the quiz
166
+ */
167
  public function load_questions( $quiz_id, $quiz_options, $is_quiz_page, $question_amount = 0 ) {
168
 
169
+ // Prepare variables.
170
  global $wpdb;
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
+ // Returns an array of all the loaded questions.
189
  return $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 ) );
190
  }
191
 
192
  /**
193
+ * Prepares Answers
194
+ *
195
+ * Prepares or creates the answer array for the quiz
196
+ *
197
+ * @since 4.0.0
198
+ * @param array $questions The questions for the quiz.
199
+ * @param bool $is_ajax Pass true if this is an ajax call.
200
+ * @return array The answers for the quiz
201
+ */
202
+ public function create_answer_array( $questions, $is_ajax = false ) {
203
+
204
+ // Load and prepare answer arrays.
205
  $mlw_qmn_answer_arrays = array();
206
  $question_list = array();
207
+ foreach ( $questions as $mlw_question_info ) {
208
+ $question_list[ $mlw_question_info->question_id ] = get_object_vars( $mlw_question_info );
209
+ if ( is_serialized( $mlw_question_info->answer_array ) && is_array( @unserialize( $mlw_question_info->answer_array ) ) ) {
210
+ $mlw_qmn_answer_array_each = @unserialize( $mlw_question_info->answer_array );
211
+ $mlw_qmn_answer_arrays[ $mlw_question_info->question_id ] = $mlw_qmn_answer_array_each;
212
+ $question_list[ $mlw_question_info->question_id ]["answers"] = $mlw_qmn_answer_array_each;
213
+ } else {
 
 
 
214
  $mlw_answer_array_correct = array(0, 0, 0, 0, 0, 0);
215
  $mlw_answer_array_correct[$mlw_question_info->correct_answer-1] = 1;
216
  $mlw_qmn_answer_arrays[$mlw_question_info->question_id] = array(
231
  }
232
 
233
  /**
234
+ * Generates Content Quiz Page
235
+ *
236
+ * Generates the content for the quiz page part of the shortcode
237
+ *
238
+ * @since 4.0.0
239
+ * @param array $qmn_quiz_options The database row of the quiz.
240
+ * @param array $qmn_quiz_questions The questions of the quiz.
241
+ * @param array $qmn_quiz_answers The answers of the quiz.
242
+ * @param array $qmn_array_for_variables The array of results for the quiz.
243
+ * @uses QMNQuizManager:display_begin_section() Creates display for beginning section
244
+ * @uses QMNQuizManager:display_questions() Creates display for questions
245
+ * @uses QMNQuizManager:display_comment_section() Creates display for comment section
246
+ * @uses QMNQuizManager:display_end_section() Creates display for end section
247
+ * @return string The content for the quiz page section
248
+ */
249
  public function display_quiz( $qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers, $qmn_array_for_variables ) {
250
 
251
  global $qmn_allowed_visit;
269
  'empty' => $qmn_quiz_options->empty_error_text
270
  );
271
 
272
+ wp_enqueue_script( 'qmn_quiz', plugins_url( '../js/qmn_quiz.js', __FILE__ ), array( 'jquery', 'jquery-ui-tooltip' ), $mlwQuizMasterNext->version );
273
  wp_localize_script( 'qmn_quiz', 'qmn_ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl
274
  wp_enqueue_script( 'math_jax', '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML' );
275
 
556
  $mlw_qmn_timer = isset($_POST["timer"]) ? intval( $_POST["timer"] ) : 0;
557
  $qmn_array_for_variables['user_id'] = get_current_user_id();
558
  $qmn_array_for_variables['timer'] = $mlw_qmn_timer;
559
+ $qmn_array_for_variables['time_taken'] = current_time( 'h:i:s A m/d/Y' );
560
  $qmn_array_for_variables['contact'] = $contact_responses;
561
 
562
  if ( !isset( $_POST["mlw_code_captcha"] ) || ( isset( $_POST["mlw_code_captcha"] ) && $_POST["mlw_user_captcha"] == $_POST["mlw_code_captcha"] ) ) {
php/class-qsm-contact-manager.php CHANGED
@@ -1,239 +1,253 @@
1
  <?php
2
 
3
- // Exit if accessed directly
4
  if ( ! defined( 'ABSPATH' ) ) exit;
5
 
6
  /**
 
7
  *
 
8
  */
9
  class QSM_Contact_Manager {
10
 
11
- private static $fields = array();
12
-
13
- function __construct() {
14
- # code...
15
- }
16
-
17
- /**
18
- * Displays the contact fields during form
19
- *
20
- * @since 5.0.0
21
- * @param $options The quiz options
22
- * @return string The HTML for the contact fields
23
- */
24
- public static function display_fields( $options ) {
25
- $return = '';
26
-
27
- // Prepare name and email values from profile if logged in
28
- $name = '';
29
- $email = '';
30
- if ( is_user_logged_in() ) {
31
- $current_user = wp_get_current_user();
32
- $name = $current_user->display_name;
33
- $email = $current_user->user_email;
34
- }
35
-
36
- // If logged in user should see fields
37
- if ( is_user_logged_in() && 1 == $options->loggedin_user_contact ) {
38
- $return = '<div style="display:none;">';
39
- }
40
-
41
- // Loads fields
42
- $fields = self::load_fields();
43
-
44
- // If fields are empty, check for backwards compatibility
45
- if ( ( empty( $fields ) || ! is_array( $fields ) ) && ( 2 != $options->user_name || 2 != $options->user_comp || 2 != $options->user_email || 2 != $options->user_phone ) ) {
46
-
47
- // Check for name field
48
- if ( 2 != $options->user_name ) {
49
- $class = '';
50
- if ( 1 == $options->user_name && 1 != $options->loggedin_user_contact ) {
51
- $class = 'mlwRequiredText qsm_required_text';
52
- }
53
- $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->name_field_text, ENT_QUOTES ) . "</span>";
54
- $return .= "<input type='text' class='$class' x-webkit-speech name='mlwUserName' value='$name' />";
55
- }
56
-
57
- // Check for comp field
58
- if ( 2 != $options->user_comp ) {
59
- $class = '';
60
- if ( 1 == $options->user_comp && 1 != $options->loggedin_user_contact ) {
61
- $class = 'mlwRequiredText qsm_required_text';
62
- }
63
- $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->business_field_text, ENT_QUOTES ) . "</span>";
64
- $return .= "<input type='text' class='$class' x-webkit-speech name='mlwUserComp' value='' />";
65
- }
66
-
67
- // Check for email field
68
- if ( 2 != $options->user_email ) {
69
- $class = '';
70
- if ( 1 == $options->user_email && 1 != $options->loggedin_user_contact ) {
71
- $class = 'mlwRequiredText qsm_required_text';
72
- }
73
- $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->email_field_text, ENT_QUOTES ) . "</span>";
74
- $return .= "<input type='email' class='mlwEmail $class' x-webkit-speech name='mlwUserEmail' value='$email' />";
75
- }
76
-
77
- // Check for phone field
78
- if ( 2 != $options->user_phone ) {
79
- $class = '';
80
- if ( 1 == $options->user_phone && 1 != $options->loggedin_user_contact ) {
81
- $class = 'mlwRequiredText qsm_required_text';
82
- }
83
- $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->phone_field_text, ENT_QUOTES ) . "</span>";
84
- $return .= "<input type='text' class='$class' x-webkit-speech name='mlwUserPhone' value='' />";
85
- }
86
- } elseif ( ! empty( $fields ) && is_array( $fields ) ) {
87
-
88
- // Cycle through each of the contact fields
89
- for ( $i = 0; $i < count( $fields ); $i++ ) {
90
-
91
- $return .= '<div class="qsm_contact_div">';
92
- $class = '';
93
- $return .= "<span class='mlw_qmn_question qsm_question'>{$fields[ $i ]['label']}</span>";
94
- $value = '';
95
- if ( 'name' == $fields[ $i ]['use'] ) {
96
- $value = $name;
97
- }
98
- if ( 'email' == $fields[ $i ]['use'] ) {
99
- $value = $email;
100
- }
101
-
102
- // Switch for contact field type
103
- switch ( $fields[ $i ]['type'] ) {
104
- case 'text':
105
- if ( ( "true" === $fields[ $i ]["required"] || true === $fields[ $i ]["required"] ) && 1 != $options->loggedin_user_contact ) {
106
- $class = 'mlwRequiredText qsm_required_text';
107
- }
108
- $return .= "<input type='text' class='$class' x-webkit-speech name='contact_field_$i' value='$value' />";
109
- break;
110
-
111
- case 'email':
112
- if ( ( "true" === $fields[ $i ]["required"] || true === $fields[ $i ]["required"] ) && 1 != $options->loggedin_user_contact ) {
113
- $class = 'mlwRequiredText qsm_required_text';
114
- }
115
- $return .= "<input type='text' class='mlwEmail $class' x-webkit-speech name='contact_field_$i' value='$value' />";
116
- break;
117
-
118
- case 'checkbox':
119
- if ( ( "true" === $fields[ $i ]["required"] || true === $fields[ $i ]["required"] ) && 1 != $options->loggedin_user_contact ) {
120
- $class = 'mlwRequiredAccept qsm_required_accept';
121
- }
122
- $return .= "<input type='checkbox' class='$class' x-webkit-speech name='contact_field_$i' value='checked' />";
123
- break;
124
-
125
- default:
126
- break;
127
- }
128
-
129
- $return .= '</div>';
130
- }
131
- }
132
-
133
- // If logged in user should see fields
134
- if ( is_user_logged_in() && 1 == $options->loggedin_user_contact ) {
135
- $return .= '</div>';
136
- }
137
-
138
- // Return contact field HTML
139
- return $return;
140
- }
141
-
142
- /**
143
- * Process the contact fields and return the values
144
- *
145
- * @since 5.0.0
146
- * @return array An array of all labels and values for the contact fields
147
- */
148
- public static function process_fields( $options ) {
149
-
150
- $responses = array();
151
-
152
- // Loads fields
153
- $fields = self::load_fields();
154
-
155
- // If fields are empty, check for backwards compatibility
156
- if ( ( empty( $fields ) || ! is_array( $fields ) ) && ( 2 != $options->user_name || 2 != $options->user_comp || 2 != $options->user_email || 2 != $options->user_phone ) ) {
157
- $responses[] = array(
158
- 'label' => 'Name',
159
- 'value' => isset( $_POST["mlwUserName"] ) ? sanitize_text_field( $_POST["mlwUserName"] ) : 'None',
160
- 'use' => 'name'
161
- );
162
- $responses[] = array(
163
- 'label' => 'Business',
164
- 'value' => isset( $_POST["mlwUserComp"] ) ? sanitize_text_field( $_POST["mlwUserComp"] ) : 'None',
165
- 'use' => 'comp'
166
- );
167
- $responses[] = array(
168
- 'label' => 'Email',
169
- 'value' => isset( $_POST["mlwUserEmail"] ) ? sanitize_text_field( $_POST["mlwUserEmail"] ) : 'None',
170
- 'use' => 'email'
171
- );
172
- $responses[] = array(
173
- 'label' => 'Phone',
174
- 'value' => isset( $_POST["mlwUserPhone"] ) ? sanitize_text_field( $_POST["mlwUserPhone"] ) : 'None',
175
- 'use' => 'phone'
176
- );
177
- } elseif ( ! empty( $fields ) && is_array( $fields ) ) {
178
- for ( $i = 0; $i < count( $fields ); $i++ ) {
179
- $fieldArray = array(
180
- 'label' => $fields[ $i ]['label'],
181
- 'value' => isset( $_POST["contact_field_$i"] ) ? sanitize_text_field( $_POST["contact_field_$i"] ) : 'None'
182
- );
183
- if ( isset( $fields[ $i ]['use'] ) ) {
184
- $fieldArray['use'] = $fields[ $i ]['use'];
185
- }
186
- $responses[] = $fieldArray;
187
- }
188
- }
189
-
190
- // For backwards compatibility, use the 'use' fields for setting $_POST values of older version of contact fields
191
- foreach ( $responses as $field ) {
192
- if ( isset( $field['use'] ) ) {
193
- if ( 'name' === $field['use'] ) {
194
- $_POST["mlwUserName"] = $field["value"];
195
- }
196
- if ( 'comp' === $field['use'] ) {
197
- $_POST["mlwUserComp"] = $field["value"];
198
- }
199
- if ( 'email' === $field['use'] ) {
200
- $_POST["mlwUserEmail"] = $field["value"];
201
- }
202
- if ( 'phone' === $field['use'] ) {
203
- $_POST["mlwUserPhone"] = $field["value"];
204
- }
205
- }
206
- }
207
-
208
- return $responses;
209
- }
210
-
211
- /**
212
- * Loads the fields
213
- *
214
- * @since 5.0.0
215
- * @uses QMNPluginHelper::get_quiz_setting
216
- * @return array The array of contact fields
217
- */
218
- public static function load_fields() {
219
- global $mlwQuizMasterNext;
220
- return maybe_unserialize( $mlwQuizMasterNext->pluginHelper->get_quiz_setting( "contact_form" ) );
221
- }
222
-
223
- /**
224
- * Saves the contact fields
225
- *
226
- * @since 5.0.0
227
- * @uses QMNPluginHelper::prepare_quiz
228
- * @uses QMNPluginHelper::update_quiz_setting
229
- */
230
- public static function save_fields( $quiz_id, $fields ) {
231
- if ( self::load_fields() === $fields ) {
232
- return true;
233
- }
234
- global $mlwQuizMasterNext;
235
- $mlwQuizMasterNext->pluginHelper->prepare_quiz( intval( $quiz_id ) );
236
- return $mlwQuizMasterNext->pluginHelper->update_quiz_setting( "contact_form", serialize( $fields ) );
237
- }
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
239
  ?>
1
  <?php
2
 
3
+ // Exit if accessed directly.
4
  if ( ! defined( 'ABSPATH' ) ) exit;
5
 
6
  /**
7
+ * This class handles the contact fields for the quiz
8
  *
9
+ * @since 5.0.0
10
  */
11
  class QSM_Contact_Manager {
12
 
13
+ /** @var array The fields loaded for the quiz. */
14
+ private static $fields = array();
15
+
16
+
17
+ /**
18
+ * Displays the contact fields during form
19
+ *
20
+ * @since 5.0.0
21
+ * @param object $options The quiz options.
22
+ * @return string The HTML for the contact fields
23
+ */
24
+ public static function display_fields( $options ) {
25
+
26
+ $return = '';
27
+ $fields_hidden = false;
28
+
29
+ // Prepare name and email values from profile if logged in.
30
+ $name = '';
31
+ $email = '';
32
+ if ( is_user_logged_in() ) {
33
+ $current_user = wp_get_current_user();
34
+ $name = $current_user->display_name;
35
+ $email = $current_user->user_email;
36
+ }
37
+
38
+ // If user is logged in and the option to allow users to edit is set to no...
39
+ if ( is_user_logged_in() && 1 == $options->loggedin_user_contact ) {
40
+ // ..then, hide the fields.
41
+ $fields_hidden = true;
42
+ $return = '<div style="display:none;">';
43
+ }
44
+
45
+ // Loads fields.
46
+ $fields = self::load_fields();
47
+
48
+ // If fields are empty and backwards-compatible fields are turned on then, use older system.
49
+ if ( ( empty( $fields ) || ! is_array( $fields ) ) && ( 2 != $options->user_name || 2 != $options->user_comp || 2 != $options->user_email || 2 != $options->user_phone ) ) {
50
+
51
+ // Check for name field.
52
+ if ( 2 != $options->user_name ) {
53
+ $class = '';
54
+ if ( 1 == $options->user_name && ! $fields_hidden ) {
55
+ $class = 'mlwRequiredText qsm_required_text';
56
+ }
57
+ $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->name_field_text, ENT_QUOTES ) . "</span>";
58
+ $return .= "<input type='text' class='$class' x-webkit-speech name='mlwUserName' value='$name' />";
59
+ }
60
+
61
+ // Check for comp field.
62
+ if ( 2 != $options->user_comp ) {
63
+ $class = '';
64
+ if ( 1 == $options->user_comp && ! $fields_hidden ) {
65
+ $class = 'mlwRequiredText qsm_required_text';
66
+ }
67
+ $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->business_field_text, ENT_QUOTES ) . "</span>";
68
+ $return .= "<input type='text' class='$class' x-webkit-speech name='mlwUserComp' value='' />";
69
+ }
70
+
71
+ // Check for email field.
72
+ if ( 2 != $options->user_email ) {
73
+ $class = '';
74
+ if ( 1 == $options->user_email && ! $fields_hidden ) {
75
+ $class = 'mlwRequiredText qsm_required_text';
76
+ }
77
+ $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->email_field_text, ENT_QUOTES ) . "</span>";
78
+ $return .= "<input type='email' class='mlwEmail $class' x-webkit-speech name='mlwUserEmail' value='$email' />";
79
+ }
80
+
81
+ // Check for phone field.
82
+ if ( 2 != $options->user_phone ) {
83
+ $class = '';
84
+ if ( 1 == $options->user_phone && ! $fields_hidden ) {
85
+ $class = 'mlwRequiredText qsm_required_text';
86
+ }
87
+ $return .= "<span class='mlw_qmn_question qsm_question'>" . htmlspecialchars_decode( $options->phone_field_text, ENT_QUOTES ) . "</span>";
88
+ $return .= "<input type='text' class='$class' x-webkit-speech name='mlwUserPhone' value='' />";
89
+ }
90
+ } elseif ( ! empty( $fields ) && is_array( $fields ) ) {
91
+
92
+ // Cycle through each of the contact fields.
93
+ $total_fields = count( $fields );
94
+ for ( $i = 0; $i < $total_fields; $i++ ) {
95
+
96
+ $return .= '<div class="qsm_contact_div">';
97
+ $class = '';
98
+ $return .= "<span class='mlw_qmn_question qsm_question'>{$fields[ $i ]['label']}</span>";
99
+ $value = '';
100
+ if ( 'name' == $fields[ $i ]['use'] ) {
101
+ $value = $name;
102
+ }
103
+ if ( 'email' == $fields[ $i ]['use'] ) {
104
+ $value = $email;
105
+ }
106
+
107
+ // Switch for contact field type.
108
+ switch ( $fields[ $i ]['type'] ) {
109
+ case 'text':
110
+ if ( ( 'true' === $fields[ $i ]["required"] || true === $fields[ $i ]["required"] ) && ! $fields_hidden ) {
111
+ $class = 'mlwRequiredText qsm_required_text';
112
+ }
113
+ $return .= "<input type='text' class='$class' x-webkit-speech name='contact_field_$i' value='$value' />";
114
+ break;
115
+
116
+ case 'email':
117
+ if ( ( 'true' === $fields[ $i ]["required"] || true === $fields[ $i ]["required"] ) && ! $fields_hidden ) {
118
+ $class = 'mlwRequiredText qsm_required_text';
119
+ }
120
+ $return .= "<input type='text' class='mlwEmail $class' x-webkit-speech name='contact_field_$i' value='$value' />";
121
+ break;
122
+
123
+ case 'checkbox':
124
+ if ( ( 'true' === $fields[ $i ]["required"] || true === $fields[ $i ]["required"] ) && ! $fields_hidden ) {
125
+ $class = 'mlwRequiredAccept qsm_required_accept';
126
+ }
127
+ $return .= "<input type='checkbox' class='$class' x-webkit-speech name='contact_field_$i' value='checked' />";
128
+ break;
129
+
130
+ default:
131
+ break;
132
+ }
133
+
134
+ $return .= '</div>';
135
+ }
136
+ }
137
+
138
+ // If logged in user should see fields.
139
+ if ( is_user_logged_in() && 1 == $options->loggedin_user_contact ) {
140
+ $return .= '</div>';
141
+ }
142
+
143
+ // Return contact field HTML.
144
+ return $return;
145
+ }
146
+
147
+ /**
148
+ * Process the contact fields and return the values
149
+ *
150
+ * @since 5.0.0
151
+ * @param object $options The quiz options.
152
+ * @return array An array of all labels and values for the contact fields
153
+ */
154
+ public static function process_fields( $options ) {
155
+
156
+ $responses = array();
157
+
158
+ // Loads the fields for the quiz.
159
+ $fields = self::load_fields();
160
+
161
+ // If fields are empty, check for backwards compatibility.
162
+ if ( ( empty( $fields ) || ! is_array( $fields ) ) && ( 2 != $options->user_name || 2 != $options->user_comp || 2 != $options->user_email || 2 != $options->user_phone ) ) {
163
+ $responses[] = array(
164
+ 'label' => 'Name',
165
+ 'value' => isset( $_POST["mlwUserName"] ) ? sanitize_text_field( $_POST["mlwUserName"] ) : 'None',
166
+ 'use' => 'name'
167
+ );
168
+ $responses[] = array(
169
+ 'label' => 'Business',
170
+ 'value' => isset( $_POST["mlwUserComp"] ) ? sanitize_text_field( $_POST["mlwUserComp"] ) : 'None',
171
+ 'use' => 'comp'
172
+ );
173
+ $responses[] = array(
174
+ 'label' => 'Email',
175
+ 'value' => isset( $_POST["mlwUserEmail"] ) ? sanitize_text_field( $_POST["mlwUserEmail"] ) : 'None',
176
+ 'use' => 'email'
177
+ );
178
+ $responses[] = array(
179
+ 'label' => 'Phone',
180
+ 'value' => isset( $_POST["mlwUserPhone"] ) ? sanitize_text_field( $_POST["mlwUserPhone"] ) : 'None',
181
+ 'use' => 'phone'
182
+ );
183
+ } elseif ( ! empty( $fields ) && is_array( $fields ) ) {
184
+ $total_fields = count( $fields );
185
+ for ( $i = 0; $i < $total_fields; $i++ ) {
186
+ $field_array = array(
187
+ 'label' => $fields[ $i ]['label'],
188
+ 'value' => isset( $_POST["contact_field_$i"] ) ? sanitize_text_field( $_POST["contact_field_$i"] ) : 'None'
189
+ );
190
+ if ( isset( $fields[ $i ]['use'] ) ) {
191
+ $field_array['use'] = $fields[ $i ]['use'];
192
+ }
193
+ $responses[] = $field_array;
194
+ }
195
+ }
196
+
197
+ // For backwards compatibility, use the 'use' fields for setting $_POST values of older version of contact fields.
198
+ foreach ( $responses as $field ) {
199
+ if ( isset( $field['use'] ) ) {
200
+ switch ( $field['use'] ) {
201
+ case 'name':
202
+ $_POST["mlwUserName"] = $field["value"];
203
+ break;
204
+
205
+ case 'comp':
206
+ $_POST["mlwUserComp"] = $field["value"];
207
+ break;
208
+
209
+ case 'email':
210
+ $_POST["mlwUserEmail"] = $field["value"];
211
+ break;
212
+
213
+ case 'phone':
214
+ $_POST["mlwUserPhone"] = $field["value"];
215
+ break;
216
+ }
217
+ }
218
+ }
219
+
220
+ return $responses;
221
+ }
222
+
223
+ /**
224
+ * Loads the fields
225
+ *
226
+ * @since 5.0.0
227
+ * @uses QMNPluginHelper::get_quiz_setting
228
+ * @return array The array of contact fields
229
+ */
230
+ public static function load_fields() {
231
+ global $mlwQuizMasterNext;
232
+ return maybe_unserialize( $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'contact_form' ) );
233
+ }
234
+
235
+ /**
236
+ * Saves the contact fields
237
+ *
238
+ * @since 5.0.0
239
+ * @uses QMNPluginHelper::prepare_quiz
240
+ * @uses QMNPluginHelper::update_quiz_setting
241
+ * @param int $quiz_id The ID for the quiz.
242
+ * @param array $fields The fields for the quiz.
243
+ */
244
+ public static function save_fields( $quiz_id, $fields ) {
245
+ if ( self::load_fields() === $fields ) {
246
+ return true;
247
+ }
248
+ global $mlwQuizMasterNext;
249
+ $mlwQuizMasterNext->pluginHelper->prepare_quiz( intval( $quiz_id ) );
250
+ return $mlwQuizMasterNext->pluginHelper->update_quiz_setting( 'contact_form', serialize( $fields ) );
251
+ }
252
  }
253
  ?>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: quiz, survey, lead, test, score, exam, questionnaire, answer, question
4
  Requires at least: 4.8
5
  Tested up to: 4.9
6
  Requires PHP: 5.2
7
- Stable tag: 5.1.5
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -110,6 +110,10 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
110
 
111
  == Changelog ==
112
 
 
 
 
 
113
  = 5.1.5 (November 27, 2017) =
114
  * IMPORTANT FIX: 5.1.4 had a fatal error for sites using out of date PHP versions. Please update to this!
115
 
4
  Requires at least: 4.8
5
  Tested up to: 4.9
6
  Requires PHP: 5.2
7
+ Stable tag: 5.1.6
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
110
 
111
  == Changelog ==
112
 
113
+ = 5.1.6 (December 25, 2017) =
114
+ * Closed Bug: Timezone ID '' is invalid - ([Issue #606](https://github.com/fpcorso/quiz_master_next/issues/606))
115
+ * Closed Bug: Required contact fields not working correctly when the loggedin_user_contact option is set to no - ([Issue #603](https://github.com/fpcorso/quiz_master_next/issues/603))
116
+
117
  = 5.1.5 (November 27, 2017) =
118
  * IMPORTANT FIX: 5.1.4 had a fatal error for sites using out of date PHP versions. Please update to this!
119