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

Version Description

(January 18, 2022) = * Bug: Fixed issues while taking quiz with logic questions. * Bug: Fixed issues with category selection on email page. * Bug: Fixed the issues with category points and score template variables. * Bug: Fixed issues when contact form is set to appears at end of the quiz. * Bug: Fixed issues with multiple quiz shortcode on a same page. * Bug: Fixed issues with number of questions per category and random questions logic. * Bug: Fixed security issues. * Bug: Fixed issues with date and current date format in template variable. * Bug: Fixed issues with QSM Theme. * Enhancement: Added option to edit quiz in admin bar. * Enhancement: Added option to disable first page on quiz. * Enhancement: Made UI improvements in QSM. * Enhancement: Made improvements in answer matching logic.

Download this release

Release Info

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

Code changes from version 7.3.7 to 7.3.8

Files changed (42) hide show
  1. css/qsm-admin.css +15 -3
  2. js/qsm-admin.js +20 -10
  3. js/qsm-quiz.js +1556 -1520
  4. mlw_quizmaster2.php +36 -4
  5. php/admin/admin-results-page.php +8 -6
  6. php/admin/functions.php +4 -0
  7. php/admin/options-page-email-tab.php +35 -33
  8. php/admin/options-page-questions-tab.php +28 -8
  9. php/admin/options-page-style-tab.php +43 -39
  10. php/admin/quiz-options-page.php +3 -3
  11. php/admin/settings-page.php +19 -0
  12. php/classes/class-qmn-plugin-helper.php +59 -6
  13. php/classes/class-qmn-quiz-manager.php +85 -97
  14. php/classes/class-qsm-emails.php +0 -18
  15. php/classes/class-qsm-install.php +26 -1
  16. php/classes/class-qsm-questions.php +12 -3
  17. php/classes/class-qsm-settings.php +1 -0
  18. php/classes/question-types/class-question-review-choice.php +37 -0
  19. php/classes/question-types/class-question-review-file-upload.php +22 -0
  20. php/classes/question-types/class-question-review-fill-in-blanks.php +96 -0
  21. php/classes/question-types/class-question-review-text.php +29 -0
  22. php/classes/question-types/class-question-review.php +77 -0
  23. php/question-types.php +161 -1363
  24. php/question-types/qsm-question-title.php +41 -0
  25. php/question-types/qsm-question-type-captcha.php +34 -0
  26. php/question-types/qsm-question-type-date.php +54 -0
  27. php/question-types/qsm-question-type-dropdown.php +69 -0
  28. php/question-types/qsm-question-type-file-upload.php +57 -0
  29. php/question-types/qsm-question-type-fill-in-the-blanks.php +63 -0
  30. php/question-types/qsm-question-type-multiple-choice-horizontal.php +96 -0
  31. php/question-types/qsm-question-type-multiple-choice.php +103 -0
  32. php/question-types/qsm-question-type-multiple-response-horizontal.php +86 -0
  33. php/question-types/qsm-question-type-multiple-response.php +87 -0
  34. php/question-types/qsm-question-type-number.php +57 -0
  35. php/question-types/qsm-question-type-opt-in.php +30 -0
  36. php/question-types/qsm-question-type-paragraph.php +57 -0
  37. php/question-types/qsm-question-type-polar.php +98 -0
  38. php/question-types/qsm-question-type-short-answer.php +59 -0
  39. php/question-types/qsm-question-type-text-or-html.php +17 -0
  40. php/template-variables.php +91 -98
  41. readme.txt +30 -1
  42. templates/qmn_primary.css +3 -1
css/qsm-admin.css CHANGED
@@ -1674,14 +1674,14 @@ td.scheduled_time_start {
1674
  }
1675
 
1676
  #show-all-variable .qsm-popup__container {
1677
- min-width: 50vw;
1678
  max-width: 1040px;
1679
  padding: 0;
1680
  }
1681
 
1682
  #show-all-variable-content {
1683
  margin-bottom: 0 !important;
1684
- padding: 20px;
1685
  margin: 0;
1686
  }
1687
 
@@ -2257,7 +2257,6 @@ td.scheduled_time_start {
2257
  .result-page-title {
2258
  margin-bottom: 10px;
2259
  }
2260
-
2261
  }
2262
 
2263
  .qsm-text-template-span{
@@ -2339,4 +2338,17 @@ td.scheduled_time_start {
2339
  input#question_search::-webkit-search-cancel-button {
2340
  outline: none;
2341
  appearance: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
2342
  }
1674
  }
1675
 
1676
  #show-all-variable .qsm-popup__container {
1677
+ min-width: 80vw;
1678
  max-width: 1040px;
1679
  padding: 0;
1680
  }
1681
 
1682
  #show-all-variable-content {
1683
  margin-bottom: 0 !important;
1684
+ padding: 20px 73px 20px 30px;
1685
  margin: 0;
1686
  }
1687
 
2257
  .result-page-title {
2258
  margin-bottom: 10px;
2259
  }
 
2260
  }
2261
 
2262
  .qsm-text-template-span{
2338
  input#question_search::-webkit-search-cancel-button {
2339
  outline: none;
2340
  appearance: none;
2341
+ }
2342
+ #mlw_quiz_wrap div#mlw_quiz_options h1#qsm_title_quiz {
2343
+ display: block;
2344
+ }
2345
+ #result_details {
2346
+ font-size: 2em;
2347
+ display: flex;
2348
+ align-items: center;
2349
+ justify-content: space-between;
2350
+ margin-bottom: 10px;
2351
+ }
2352
+ input#duplicate_questions {
2353
+ margin-left: 10px;
2354
  }
js/qsm-admin.js CHANGED
@@ -479,10 +479,10 @@ var QSMAdmin;
479
  }
480
  });
481
  }
482
-
483
-
484
  });
485
-
486
  jQuery('.qsm_audit_data').click(function (e) {
487
  e.preventDefault();
488
  MicroModal.show('qsm_fetch_audit_data');
@@ -571,10 +571,6 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
571
  jQuery('.my-color-field').wpColorPicker();
572
  }
573
  });
574
- jQuery(document).on('click', '#qsm-save-theme-settings', function(e){
575
- e.preventDefault();
576
- jQuery('.qsm-theme-settings-frm').submit();
577
- });
578
  });
579
  }
580
  }
@@ -1671,10 +1667,10 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1671
  });
1672
  var data = {
1673
  action: 'qsm_save_pages',
1674
- pages: pages,
1675
- qpages: qpages,
1676
  quiz_id: qsmQuestionSettings.quizID,
1677
  nonce: qsmQuestionSettings.saveNonce,
 
 
1678
  };
1679
 
1680
  jQuery.ajax(ajaxurl, {
@@ -1971,7 +1967,13 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1971
  $('#answers .answer-points').val('').hide();
1972
  }
1973
  }
1974
-
 
 
 
 
 
 
1975
 
1976
  if (answer[5] == 'rich' && qsmQuestionSettings.qsm_user_ve === 'true') {
1977
  var textarea_id = 'answer-' + answer[4] + '-' + answer[3];
@@ -2535,6 +2537,12 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2535
  tinyMCE.get('question-text').setContent('');
2536
  }
2537
  }
 
 
 
 
 
 
2538
 
2539
  // show points field only for polar in survey and simple form
2540
  if (qsmQuestionSettings.form_type != 0) {
@@ -2544,6 +2552,8 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2544
  $('.answer-points').val('').hide();
2545
  }
2546
  }
 
 
2547
  $('.qsm_hide_for_other').hide();
2548
  if ($('.qsm_show_question_type_' + question_val).length > 0) {
2549
  $('.qsm_show_question_type_' + question_val).show();
479
  }
480
  });
481
  }
482
+
483
+
484
  });
485
+
486
  jQuery('.qsm_audit_data').click(function (e) {
487
  e.preventDefault();
488
  MicroModal.show('qsm_fetch_audit_data');
571
  jQuery('.my-color-field').wpColorPicker();
572
  }
573
  });
 
 
 
 
574
  });
575
  }
576
  }
1667
  });
1668
  var data = {
1669
  action: 'qsm_save_pages',
 
 
1670
  quiz_id: qsmQuestionSettings.quizID,
1671
  nonce: qsmQuestionSettings.saveNonce,
1672
+ pages: pages,
1673
+ qpages: qpages,
1674
  };
1675
 
1676
  jQuery.ajax(ajaxurl, {
1967
  $('#answers .answer-points').val('').hide();
1968
  }
1969
  }
1970
+ if (qsmQuestionSettings.form_type == 0) {
1971
+ if (questionType == 14) {
1972
+ $('.correct-answer').hide();
1973
+ } else {
1974
+ $('.correct-answer').show();
1975
+ }
1976
+ }
1977
 
1978
  if (answer[5] == 'rich' && qsmQuestionSettings.qsm_user_ve === 'true') {
1979
  var textarea_id = 'answer-' + answer[4] + '-' + answer[3];
2537
  tinyMCE.get('question-text').setContent('');
2538
  }
2539
  }
2540
+ if (14 == question_val) {
2541
+ $('.correct-answer').hide();
2542
+ }
2543
+ else{
2544
+ $('.correct-answer').show();
2545
+ }
2546
 
2547
  // show points field only for polar in survey and simple form
2548
  if (qsmQuestionSettings.form_type != 0) {
2552
  $('.answer-points').val('').hide();
2553
  }
2554
  }
2555
+
2556
+
2557
  $('.qsm_hide_for_other').hide();
2558
  if ($('.qsm_show_question_type_' + question_val).length > 0) {
2559
  $('.qsm_show_question_type_' + question_val).show();
js/qsm-quiz.js CHANGED
@@ -7,1528 +7,1564 @@
7
  * being deprecated and replaced with rewritten newer functions
8
  **************************/
9
 
10
- var QSM;
11
- var QSMPageTimer;
12
- (function ($) {
13
- QSM = {
14
- /**
15
- * Initializes all quizzes or surveys on the page
16
- */
17
- init: function () {
18
- // Makes sure we have quizzes on this page
19
- if (typeof qmn_quiz_data != 'undefined' && qmn_quiz_data) {
20
- // hide the recaptcha by default
21
- $('.g-recaptcha').hide();
22
- // Cycle through all quizzes
23
- _.each(qmn_quiz_data, function (quiz) {
24
- quizID = parseInt(quiz.quiz_id);
25
- QSM.initPagination(quizID);
26
-
27
- if (quiz.hasOwnProperty('pagination') || quiz.qpages.hasOwnProperty(2)) {
28
- qsmEndTimeTakenTimer();
29
- jQuery('#timer').val(0);
30
- jQuery("input[name='timer_ms']").val(0);
31
- quizType = 'paginated';
32
- }
33
-
34
- if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
35
- qsmEndTimeTakenTimer();
36
- jQuery('#timer').val(0);
37
- jQuery("input[name='timer_ms']").val(0);
38
- QSMPageTimer.endPageTimer(quizID, true);
39
- }
40
- if (quiz.hasOwnProperty('timer_limit') && 0 != quiz.timer_limit) {
41
- qsmEndTimeTakenTimer();
42
- jQuery('#timer').val(0);
43
- jQuery("input[name='timer_ms']").val(0);
44
- QSM.initTimer(quizID);
45
- quizType = 'timer';
46
- }
47
- });
48
- }
49
- },
50
-
51
- /**
52
- * Sets up timer for a quiz
53
- *
54
- * @param int quizID The ID of the quiz
55
- */
56
- initTimer: function (quizID) {
57
-
58
- jQuery(document).trigger('qsm_init_timer_before', [quizID]);
59
-
60
- // Gets our form
61
- var $quizForm = QSM.getQuizForm(quizID);
62
-
63
- // Creates timer status key.
64
- qmn_quiz_data[quizID].timerStatus = false;
65
-
66
- // If we are using the newer pagination system...
67
- if (0 < $quizForm.children('.qsm-page').length) {
68
- // If there is a first page...
69
- if (qmn_quiz_data[quizID].hasOwnProperty('first_page') && !qmn_quiz_data[quizID].first_page) {
70
- QSM.activateTimer(quizID);
71
- $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
72
- }
73
- // ...else, we must be using the questions per page option.
74
- } else {
75
- if (qmn_quiz_data[quizID].hasOwnProperty('pagination') && qmn_quiz_data[quizID].first_page) {
76
- $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.mlw_next').on('click', function (event) {
77
- event.preventDefault();
78
- if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
79
- var start_timer = parseInt(qmn_quiz_data[quizID].advanced_timer.start_timer_page);
80
- if ($('#quizForm' + quizID).closest('.qmn_quiz_container').find('.qmn_pagination > .slide_number_hidden').val() == start_timer) {
81
- QSM.activateTimer(quizID);
82
- $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
83
- }
84
- } else {
85
- if (!qmn_quiz_data[quizID].timerStatus && (0 == $('.quiz_begin:visible').length || (1 == $('.quiz_begin:visible').length && qmnValidatePage('quizForm' + quizID)))) {
86
- QSM.activateTimer(quizID);
87
- $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
88
- }
89
- }
90
- });
91
- } else {
92
- QSM.activateTimer(quizID);
93
- $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
94
- }
95
- }
96
- jQuery(document).trigger('qsm_init_timer_after', [quizID]);
97
- },
98
- /**
99
- * Starts the timer for the quiz.
100
- *
101
- * @param int quizID The ID of the quiz.
102
- */
103
- activateTimer: function (quizID) {
104
- timer_ms = jQuery("input[name='timer_ms']").val();
105
- if (timer_ms == 0) {
106
- qsmTimerInterval = setInterval(qmnTimeTakenTimer, 1000);
107
- jQuery("input[name='timer_ms']").each(function () {
108
- var timems = qsmTimeInMS();
109
- jQuery(this).val(timems);
110
- });
111
- }
112
-
113
- jQuery(document).trigger('qsm_activate_time_before', [quizID, qmn_quiz_data]);
114
- // Gets our form.
115
- var $timer = QSM.getTimer(quizID);
116
-
117
- // Sets up our variables.
118
- qmn_quiz_data[quizID].timerStatus = true;
119
- var seconds = 0;
120
-
121
- // Calculates starting time.
122
- var timerStarted = localStorage.getItem('mlw_started_quiz' + quizID);
123
- var timerRemaning = localStorage.getItem('mlw_time_quiz' + quizID);
124
- if ('yes' == timerStarted && 0 < timerRemaning) {
125
- seconds = parseInt(timerRemaning);
126
- } else {
127
- seconds = parseFloat(qmn_quiz_data[quizID].timer_limit) * 60;
128
- }
129
- qmn_quiz_data[quizID].timerRemaning = seconds;
130
-
131
- //hidden timer
132
- jQuery(".hiddentimer").html(seconds);
133
-
134
- // Makes the timer appear.
135
- $timer.show();
136
- $timer.text(QSM.secondsToTimer(seconds));
137
-
138
- // Sets up timer interval.
139
- if (!isNaN(qmn_quiz_data[quizID].timerRemaning)) {
140
- clearInterval(qmn_quiz_data[quizID].timerInterval);
141
- qmn_quiz_data[quizID].timerInterval = setInterval(QSM.timer, 1000, quizID);
142
- }
143
- jQuery(document).trigger('qsm_activate_time_after', [quizID, qmn_quiz_data]);
144
- },
145
- /**
146
- * Reduces the timer by one second and checks if timer is 0
147
- *
148
- * @param int quizID The ID of the quiz.
149
- */
150
- timer: function (quizID) {
151
- qmn_quiz_data[quizID].timerRemaning -= 1;
152
- if (0 > qmn_quiz_data[quizID].timerRemaning) {
153
- qmn_quiz_data[quizID].timerRemaning = 0;
154
- }
155
- var secondsRemaining = qmn_quiz_data[quizID].timerRemaning;
156
- var display = QSM.secondsToTimer(secondsRemaining);
157
- var systemTime=new Date().getTime()/1000;
158
- systemTime=Math.round(systemTime);
159
- if('1'===qmn_quiz_data[quizID].not_allow_after_expired_time && systemTime > qmn_quiz_data[quizID].scheduled_time_end ){
160
- MicroModal.show('modal-4');
161
- return false;
162
- }
163
- // Sets our local storage values for the timer being started and current timer value.
164
- localStorage.setItem('mlw_time_quiz' + quizID, secondsRemaining);
165
- localStorage.setItem('mlw_started_quiz' + quizID, "yes");
166
-
167
- // Updates timer element and title on browser tab.
168
- var $timer = QSM.getTimer(quizID);
169
- $timer.text(display);
170
- document.title = display + ' ' + qsmTitleText;
171
-
172
- /*CUSTOM TIMER*/
173
- if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer') && qmn_quiz_data[quizID].advanced_timer.timer_design == 'big_timer') {
174
- $(".second.circle").parent('.mlw_quiz_form').addClass('qsm_big_timer');
175
- $(".second.circle").show();
176
- $(".second.circle strong").html(display);
177
- var datashow = ($(".hiddentimer").html() - secondsRemaining) / $(".hiddentimer").html();
178
- $(".second.circle").circleProgress({
179
- startAngle: 11,
180
- value: datashow,
181
- animation: false,
182
- fill: { gradient: ["#00bb40", "#00511c"] }
183
- });
184
- }
185
-
186
- var $quizForm = QSM.getQuizForm(quizID);
187
- var total_seconds = parseFloat(qmn_quiz_data[quizID].timer_limit) * 60;
188
- var ninety_sec = total_seconds - (total_seconds * 90 / 100);
189
- if (ninety_sec == secondsRemaining) {
190
- $quizForm.closest('.qmn_quiz_container').find('.qsm_ninety_warning').fadeIn();
191
- }
192
-
193
- // If timer is run out, disable fields.
194
- if (0 >= secondsRemaining) {
195
- clearInterval(qmn_quiz_data[quizID].timerInterval);
196
- $(".mlw_qmn_quiz input:radio").attr('disabled', true);
197
- $(".mlw_qmn_quiz input:checkbox").attr('disabled', true);
198
- $(".mlw_qmn_quiz select").attr('disabled', true);
199
- $(".mlw_qmn_question_comment").attr('disabled', true);
200
- $(".mlw_answer_open_text").attr('disabled', true);
201
- $(".mlw_answer_number").attr('readonly', true);
202
-
203
- $quizForm.closest('.qmn_quiz_container').addClass('qsm_timer_ended');
204
- $quizForm.closest('.qmn_quiz_container').prepend('<p class="qmn_error_message" style="color: red;">Quiz time is over</p>');
205
- if (qmn_quiz_data[quizID].enable_result_after_timer_end == 1) {
206
- $quizForm.closest('.qmn_quiz_container').find('.qsm-submit-btn').trigger('click');
207
- } else {
208
- MicroModal.show('modal-3');
209
- }
210
- return;
211
- }
212
- },
213
- /**
214
- * Clears timer interval
215
- *
216
- * @param int quizID The ID of the quiz
217
- */
218
- endTimer: function (quizID) {
219
- localStorage.setItem('mlw_time_quiz' + quizID, 'completed');
220
- localStorage.setItem('mlw_started_quiz' + quizID, 'no');
221
- document.title = qsmTitleText;
222
- if (typeof qmn_quiz_data[quizID].timerInterval != 'undefined') {
223
- clearInterval(qmn_quiz_data[quizID].timerInterval);
224
- }
225
- jQuery(document).trigger('qsm_end_timer', [quizID, qmn_quiz_data]);
226
- },
227
- /**
228
- * Converts seconds to 00:00:00 format
229
- *
230
- * @param int seconds The number of seconds
231
- * @return string A string in H:M:S format
232
- */
233
- secondsToTimer: function (seconds) {
234
- var formattedTime = '';
235
- seconds = parseInt(seconds);
236
-
237
- // Prepares the hours part.
238
- var hours = Math.floor(seconds / 3600);
239
- if (0 === hours) {
240
- formattedTime = '00:';
241
- } else if (10 > hours) {
242
- formattedTime = '0' + hours + ':';
243
- } else {
244
- formattedTime = hours + ':';
245
- }
246
-
247
- // Prepares the minutes part.
248
- var minutes = Math.floor((seconds % 3600) / 60);
249
- if (0 === minutes) {
250
- formattedTime = formattedTime + '00:';
251
- } else if (10 > minutes) {
252
- formattedTime = formattedTime + '0' + minutes + ':';
253
- } else {
254
- formattedTime = formattedTime + minutes + ':';
255
- }
256
-
257
- // Prepares the seconds part.
258
- var remainder = Math.floor((seconds % 60));
259
- if (0 === remainder) {
260
- formattedTime = formattedTime + '00';
261
- } else if (10 > remainder) {
262
- formattedTime = formattedTime + '0' + remainder;
263
- } else {
264
- formattedTime = formattedTime + remainder;
265
- }
266
- return formattedTime;
267
- },
268
- /**
269
- * Gets the jQuery object for the timer
270
- */
271
- getTimer: function (quizID) {
272
- var $quizForm = QSM.getQuizForm(quizID);
273
- return $quizForm.children('.mlw_qmn_timer');
274
- },
275
-
276
- /**
277
- * Sets up pagination for a quiz
278
- *
279
- * @param int quizID The ID of the quiz.
280
- */
281
- initPagination: function (quizID) {
282
- var $quizForm = QSM.getQuizForm(quizID);
283
-
284
-
285
- /**
286
- *
287
- * CHecking if the quiz is random
288
- */
289
- $is_random = $('.qmn_quiz_container').hasClass('random');
290
- if($is_random){
291
- QSM.goToPage(quizID, 1);
292
- }
293
- else if (0 < $quizForm.children('.qsm-page').length) {
294
- $quizForm.children('.qsm-page').hide();
295
- template = wp.template('qsm-pagination-' + quizID);
296
- $quizForm.append(template());
297
- if ($quizForm.find('.qsm-pagination > .current_page_hidden').length == 0) {
298
- $quizForm.find('.qsm-pagination').append('<input type="hidden" value="0" name="current_page" class="current_page_hidden" />');
299
- }
300
- if ('1' == qmn_quiz_data[quizID].progress_bar) {
301
- jQuery(document).trigger('qsm_init_progressbar_before', [quizID, qmn_quiz_data]);
302
- $('#quizForm' + quizID).find('.qsm-progress-bar').show();
303
- qmn_quiz_data[quizID].bar = new ProgressBar.Line('#quizForm' + quizID + ' .qsm-progress-bar', {
304
- strokeWidth: 2,
305
- easing: 'easeInOut',
306
- duration: 1400,
307
- color: '#3498db',
308
- trailColor: '#eee',
309
- trailWidth: 1,
310
- svgStyle: { width: '100%', height: '100%' },
311
- text: {
312
- style: {
313
- // color: '#999',
314
- position: 'absolute',
315
- padding: 0,
316
- margin: 0,
317
- top: 0,
318
- right: '10px',
319
- 'font-size': '13px',
320
- 'font-weight': 'bold',
321
- transform: null
322
- },
323
- autoStyleContainer: false
324
- },
325
- from: { color: '#3498db' },
326
- to: { color: '#ED6A5A' },
327
- step: function (state, bar) {
328
- //bar.setText(Math.round(bar.value() * 100) + ' %');
329
- }
330
- });
331
- jQuery(document).trigger('qsm_init_progressbar_after', [quizID, qmn_quiz_data]);
332
- }
333
- QSM.goToPage(quizID, 1);
334
-
335
- $quizForm.find('.qsm-pagination .qsm-next').on('click', function (event) {
336
- jQuery(document).trigger('qsm_next_button_click_before', [quizID]);
337
- event.preventDefault();
338
- QSM.nextPage(quizID);
339
- var $container = jQuery('#quizForm' + quizID).closest('.qmn_quiz_container');
340
- if (qmn_quiz_data[quizID].disable_scroll_next_previous_click != 1) {
341
- qsmScrollTo($container);
342
- }
343
- jQuery(document).trigger('qsm_next_button_click_after', [quizID]);
344
- });
345
- $quizForm.find('.qsm-pagination .qsm-previous').on('click', function (event) {
346
- jQuery(document).trigger('qsm_previous_button_click_before', [quizID]);
347
- event.preventDefault();
348
- QSM.prevPage(quizID);
349
- var $container = jQuery('#quizForm' + quizID).closest('.qmn_quiz_container');
350
- if (qmn_quiz_data[quizID].disable_scroll_next_previous_click != 1) {
351
- qsmScrollTo($container);
352
- }
353
- jQuery(document).trigger('qsm_previous_button_click_after', [quizID]);
354
- });
355
- }
356
- },
357
- /**
358
- * Navigates quiz to specific page
359
- *
360
- * @param int pageNumber The number of the page
361
- */
362
- goToPage: function (quizID, pageNumber) {
363
- jQuery(document).trigger('qsm_go_to_page_before', [quizID, pageNumber]);
364
- var $quizForm = QSM.getQuizForm(quizID);
365
- var $pages = $quizForm.children('.qsm-page');
366
- var $currentPage = $quizForm.children('.qsm-page:nth-of-type(' + pageNumber + ')');
367
- $pages.hide();
368
- $currentPage.show();
369
-
370
- if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
371
- QSMPageTimer.endPageTimer(quizID);
372
- QSMPageTimer.initPageTimer(quizID, $currentPage);
373
- }
374
-
375
- $quizForm.find('.current_page_hidden').val(pageNumber - 1);
376
- $quizForm.find('.qsm-previous').hide();
377
- $quizForm.find('.qsm-next').hide();
378
- $quizForm.find('.qsm-submit-btn').hide();
379
- $quizForm.find('.g-recaptcha').hide();
380
- if (pageNumber < $pages.length) {
381
-
382
- $quizForm.find('.qsm-next').show();
383
- } else {
384
- $quizForm.find('.qsm-submit-btn').show();
385
- $quizForm.find('.g-recaptcha').show();
386
- }
387
- if (1 < pageNumber) {
388
- $quizForm.find('.qsm-previous').show();
389
- }
390
- if (1 == $currentPage.data('prevbtn')) {
391
- $quizForm.find('.qsm-previous').hide();
392
- }
393
- if ('1' == qmn_quiz_data[quizID].progress_bar) {
394
- var current_page = jQuery('#quizForm' + quizID).find('.current_page_hidden').val();
395
- var total_page_length = $pages.length - 1;
396
- if (qmn_quiz_data[quizID].contact_info_location == 0) {
397
- //Do nothing.
398
- } else if (qmn_quiz_data[quizID].contact_info_location == 1) {
399
- if ($quizForm.children('.qsm-page').find('.qsm_contact_div ').length > 0) {
400
- //total_page_length = total_page_length - 1;
401
- }
402
- }
403
- var animate_value = current_page / total_page_length;
404
- if (animate_value <= 1) {
405
- qmn_quiz_data[quizID].bar.animate(animate_value);
406
- var old_text = jQuery('#quizForm' + quizID).find('.progressbar-text').text().replace(' %', '');
407
- var new_text = Math.round(animate_value * 100);
408
- jQuery({
409
- Counter: old_text
410
- }).animate({
411
- Counter: new_text
412
- }, {
413
- duration: 1000,
414
- easing: 'swing',
415
- step: function () {
416
- jQuery('#quizForm' + quizID).find('.progressbar-text').text(Math.round(this.Counter) + ' %');
417
- }
418
- });
419
- }
420
- }
421
- QSM.savePage(quizID, pageNumber);
422
- jQuery(document).trigger('qsm_go_to_page_after', [quizID, pageNumber]);
423
- },
424
- /**
425
- * Moves forward or backwards through the pages
426
- *
427
- * @param int quizID The ID of the quiz
428
- * @param int difference The number of pages to forward or back
429
- */
430
- changePage: function (quizID, difference) {
431
- var page = QSM.getPage(quizID);
432
- if(qmn_quiz_data[quizID].hasOwnProperty('first_page') && qmn_quiz_data[quizID].first_page){
433
- if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
434
- var start_timer = parseInt(qmn_quiz_data[quizID].advanced_timer.start_timer_page);
435
- if ( page == start_timer ) { // check current page
436
- QSM.activateTimer(quizID);
437
- $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
438
- }
439
- } else {
440
- if (!qmn_quiz_data[quizID].timerStatus ) {
441
- QSM.activateTimer(quizID);
442
- $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
443
- }
444
- }
445
- }
446
- page += difference;
447
- QSM.goToPage(quizID, page);
448
- },
449
- nextPage: function (quizID) {
450
- if (qmnValidatePage('quizForm' + quizID)) {
451
- QSM.changePage(quizID, 1);
452
- }
453
- },
454
- prevPage: function (quizID) {
455
- QSM.changePage(quizID, -1);
456
- },
457
- savePage: function (quizID, pageNumber) {
458
- sessionStorage.setItem('quiz' + quizID + 'page', pageNumber);
459
- },
460
- getPage: function (quizID) {
461
- pageNumber = parseInt(sessionStorage.getItem('quiz' + quizID + 'page'));
462
- if (isNaN(pageNumber) || null == pageNumber) {
463
- pageNumber = 1;
464
- }
465
- return pageNumber;
466
- },
467
- /**
468
- * Scrolls to the top of supplied element
469
- *
470
- * @param jQueryObject The jQuery version of an element. i.e. $('#quizForm3')
471
- */
472
- scrollTo: function ($element) {
473
- jQuery('html, body').animate(
474
- {
475
- scrollTop: $element.offset().top - 150
476
- },
477
- 1000);
478
- },
479
- /**
480
- * Gets the jQuery object of the quiz form
481
- */
482
- getQuizForm: function (quizID) {
483
- return $('#quizForm' + quizID);
484
- }
485
- };
486
-
487
- QSMPageTimer = {
488
- /**
489
- * Init Page Timer
490
- */
491
- initPageTimer: function (quizID, $currentpage) {
492
- jQuery(document).trigger('qsm_init_page_timer_before', [quizID, $currentpage]);
493
- var $quizForm = QSM.getQuizForm(quizID);
494
- var pid = $currentpage.data('pid');
495
- if (undefined != pid) {
496
- var $qpages = qmn_quiz_data[quizID].qpages;
497
- var $curr_page_opt = $qpages[pid];
498
- if ($curr_page_opt.hasOwnProperty('pagetimer') && 0 != $curr_page_opt.pagetimer) {
499
- var $timer_box = $currentpage.find('.qsm-pagetimer');
500
- var seconds = 0;
501
- var timerStarted = localStorage.getItem('mlw_started_q' + quizID + '_page' + pid);
502
- var timerStoped = localStorage.getItem('mlw_stoped_q' + quizID + '_page' + pid);
503
- var timerRemaning = localStorage.getItem('mlw_time_q' + quizID + '_page' + pid);
504
- if (timerStoped != 'undefined' && timerStoped > 0) {
505
- seconds = timerStoped;
506
- } else {
507
- if ('yes' == timerStarted) {
508
- if (0 < timerRemaning) {
509
- seconds = parseInt(timerRemaning);
510
- }
511
- } else {
512
- seconds = parseFloat($curr_page_opt.pagetimer) * 60;
513
- }
514
- }
515
- qmn_quiz_data[quizID].qpages[pid].timerRemaning = seconds;
516
- /* Makes the timer appear. */
517
- $timer_box.show();
518
- $timer_box.text(QSMPageTimer.secondsToTimer(seconds));
519
- /* Sets up timer interval. */
520
- qmn_quiz_data[quizID].qpages[pid].timerInterval = setInterval(QSMPageTimer.timer, 1000, quizID, pid, $timer_box);
521
- }
522
- $currentpage.find('.page_intro_wrapper video').each(function () {
523
- var $this = jQuery(this);
524
- var src = $this.find('source').attr('src');
525
- $this.attr('src', src)
526
- $this.load();
527
- $this.get(0).play();
528
- });
529
- }
530
- jQuery(document).trigger('qsm_init_page_timer_after', [quizID, $currentpage]);
531
- },
532
- /**
533
- * Reduces the timer by one second and checks if timer is 0
534
- * @param int quizID The ID of the quiz.
535
- */
536
- timer: function (quizID, pid, $timer_box) {
537
- var $quizForm = QSM.getQuizForm(quizID);
538
- var $page = qmn_quiz_data[quizID].qpages[pid];
539
- qmn_quiz_data[quizID].qpages[pid].timerRemaning -= 1;
540
- if (0 > qmn_quiz_data[quizID].qpages[pid].timerRemaning) {
541
- qmn_quiz_data[quizID].qpages[pid].timerRemaning = 0;
542
- }
543
- var total_seconds = parseFloat($page.pagetimer) * 60;
544
- var secondsRemaining = qmn_quiz_data[quizID].qpages[pid].timerRemaning;
545
- var display = QSMPageTimer.secondsToTimer(secondsRemaining);
546
- $timer_box.text(display);
547
- var pageTimeTaken = total_seconds - secondsRemaining;
548
- jQuery('#pagetime_' + pid).val(pageTimeTaken);
549
- /* Sets our local storage values for the timer being started and current timer value. */
550
- localStorage.setItem('mlw_started_q' + quizID + '_page' + pid, "yes");
551
- localStorage.setItem('mlw_time_q' + quizID + '_page' + pid, secondsRemaining);
552
- if ($page.hasOwnProperty('pagetimer_warning') && 0 != $page.pagetimer_warning) {
553
- var page_warning_sec = parseFloat($page.pagetimer_warning) * 60;
554
- if (page_warning_sec == secondsRemaining) {
555
- $timer_box.parents('.qsm-page').find('.qsm-pagetimer-warning').fadeIn();
556
- }
557
- }
558
- /* If timer is run out, disable fields. */
559
- if (0 >= secondsRemaining) {
560
- clearInterval(qmn_quiz_data[quizID].qpages[pid].timerInterval);
561
-
562
- $(".qsm-page:visible input:radio").attr('disabled', true);
563
- $(".qsm-page:visible input:checkbox").attr('disabled', true);
564
- $(".qsm-page:visible select").attr('disabled', true);
565
- $(".qsm-page:visible .mlw_qmn_question_comment").attr('disabled', true);
566
- $(".qsm-page:visible .mlw_answer_open_text").attr('disabled', true);
567
- $(".qsm-page:visible .mlw_answer_number").attr('disabled', true);
568
-
569
- QSMPageTimer.endPageTimer(quizID);
570
- MicroModal.show('modal-page-1');
571
- return;
572
- }
573
- },
574
- /**
575
- * Clears timer interval
576
- * @param int quizID The ID of the quiz
577
- */
578
- endPageTimer: function (quizID, clearStorage = false) {
579
- jQuery.each(qmn_quiz_data[quizID].qpages, function (i, value) {
580
- if (value.hasOwnProperty('pagetimer') && 0 != value.pagetimer) {
581
- if (clearStorage) {
582
- localStorage.removeItem('mlw_started_q' + quizID + '_page' + value.id);
583
- localStorage.removeItem('mlw_stoped_q' + quizID + '_page' + value.id);
584
- localStorage.removeItem('mlw_time_q' + quizID + '_page' + value.id);
585
- }
586
- var secondsRemaining = qmn_quiz_data[quizID].qpages[value.id].timerRemaning;
587
- localStorage.setItem('mlw_stoped_q' + quizID + '_page' + value.id, secondsRemaining);
588
- localStorage.setItem('mlw_time_q' + quizID + '_page' + value.id, 'completed');
589
- if (typeof qmn_quiz_data[quizID].qpages[value.id].timerInterval != 'undefined') {
590
- clearInterval(qmn_quiz_data[quizID].qpages[value.id].timerInterval);
591
- }
592
- }
593
- });
594
- },
595
- /**
596
- * Converts seconds to 00:00:00 format
597
- * @param int seconds The number of seconds
598
- * @return string A string in H:M:S format
599
- */
600
- secondsToTimer: function (seconds) {
601
- var formattedTime = '';
602
- seconds = parseInt(seconds);
603
- var hours = Math.floor(seconds / 3600);
604
- if (0 === hours) {
605
- formattedTime = '00:';
606
- } else if (10 > hours) {
607
- formattedTime = '0' + hours + ':';
608
- } else {
609
- formattedTime = hours + ':';
610
- }
611
- var minutes = Math.floor((seconds % 3600) / 60);
612
- if (0 === minutes) {
613
- formattedTime = formattedTime + '00:';
614
- } else if (10 > minutes) {
615
- formattedTime = formattedTime + '0' + minutes + ':';
616
- } else {
617
- formattedTime = formattedTime + minutes + ':';
618
- }
619
- var remainder = Math.floor((seconds % 60));
620
- if (0 === remainder) {
621
- formattedTime = formattedTime + '00';
622
- } else if (10 > remainder) {
623
- formattedTime = formattedTime + '0' + remainder;
624
- } else {
625
- formattedTime = formattedTime + remainder;
626
- }
627
- return formattedTime;
628
- },
629
- }
630
-
631
- // On load code
632
- $(function () {
633
- qmnDoInit();
634
- });
635
- }(jQuery));
636
-
637
- // Global Variables
638
- var qsmTitleText = document.title;
639
-
640
- /**
641
- * Validates an email ID.
642
- *
643
- * @param email The Email Id to validate.
644
- * @returns Boolean
645
- */
646
- function isEmail(email) {
647
- var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
648
- if (!regex.test(email)) {
649
- return false;
650
- } else {
651
- return true;
652
- }
653
- }
654
-
655
-
656
- /**
 
 
 
 
 
 
 
 
657
  * Limit multiple response based on question limit
658
  * @returns {undefined}
659
  */
660
- function qsmCheckMR(event, limit) {
661
- var checked = jQuery(event).parents('.quiz_section').find(':checkbox:checked').length;
662
- if (checked > limit) {
663
- event.checked = false;
664
- if (jQuery(event).parents('.quiz_section').find('.multi-checkbox-limit-reach').length == 0) {
665
- jQuery(event).parents('.quiz_section').append('<span class="multi-checkbox-limit-reach">' + qmn_ajax_object.multicheckbox_limit_reach + '</span>');
666
- }
667
- } else {
668
- jQuery(event).parents('.quiz_section').find('.multi-checkbox-limit-reach').remove();
669
- }
670
- }
671
-
672
- function qmnDoInit() {
673
- // Legacy init.
674
- qmnInit();
675
-
676
- // Call main initialization.
677
- qsminstance = QSM.init();
678
-
679
- jQuery(".qsm-quiz-container").on("click", ".mlw_next", function () {
680
- if (quizType == 'paginated') {
681
- timer_ms = jQuery("input[name='timer_ms']").val();
682
- if (timer_ms == 0) {
683
- qsmTimerInterval = setInterval(qmnTimeTakenTimer, 1000);
684
- jQuery("input[name='timer_ms']").each(function () {
685
- var timems = qsmTimeInMS();
686
- jQuery(this).val(timems);
687
- });
688
- }
689
- }
690
- });
691
- }
692
-
693
- function qmnTimeTakenTimer() {
694
- var x = +jQuery('#timer').val();
695
- if (NaN === x) {
696
- x = 0;
697
- }
698
- x = x + 1;
699
- jQuery('#timer').val(x);
700
- }
701
-
702
- function qsmEndTimeTakenTimer() {
703
- clearInterval(qsmTimerInterval);
704
- }
705
-
706
- function qsmTimeInMS() {
707
- var d = new Date();
708
- var n = d.getTime();
709
- return n;
710
- }
711
-
712
- function qmnClearField(field) {
713
- if (field.defaultValue == field.value) field.value = '';
714
- }
715
-
716
- function qsmScrollTo($element) {
717
- if ($element.length > 0) {
718
- jQuery(document).trigger('qsm_scroll_to_top_before', [$element]);
719
- jQuery('html, body').animate({ scrollTop: $element.offset().top - 150 }, 1000);
720
- jQuery(document).trigger('qsm_scroll_to_top_after', [$element]);
721
- }
722
- }
723
-
724
- function qmnDisplayError(message, field, quiz_form_id) {
725
- jQuery('#' + quiz_form_id + ' .qmn_error_message_section').addClass('qmn_error_message');
726
- jQuery('#' + quiz_form_id + ' .qmn_error_message').text(message);
727
- field.closest('.quiz_section').addClass('qmn_error');
728
- }
729
-
730
- function qmnResetError(quiz_form_id) {
731
- jQuery('#' + quiz_form_id + ' .qmn_error_message').text('');
732
- jQuery('#' + quiz_form_id + ' .qmn_error_message_section').removeClass('qmn_error_message');
733
- jQuery('#' + quiz_form_id + ' .quiz_section').removeClass('qmn_error');
734
- }
735
-
736
- function qmnValidation(element, quiz_form_id) {
737
- jQuery(document).trigger('qsm_before_validation', [element, quiz_form_id]);
738
- var result = true;
739
- var quiz_id = +jQuery('#' + quiz_form_id).find('.qmn_quiz_id').val();
740
- var email_error = qmn_quiz_data[quiz_id].error_messages.email;
741
- var number_error = qmn_quiz_data[quiz_id].error_messages.number;
742
- var empty_error = qmn_quiz_data[quiz_id].error_messages.empty;
743
- var incorrect_error = qmn_quiz_data[quiz_id].error_messages.incorrect;
744
- qmnResetError(quiz_form_id);
745
- jQuery(element).each(function () {
746
- if (jQuery(this).attr('class')) {
747
- if (jQuery(this).attr('class').indexOf('mlwEmail') !== -1 && this.value !== "") {
748
- // Remove any trailing and preceeding space.
749
- var x = jQuery.trim(this.value);
750
- if (!isEmail(x)) {
751
- qmnDisplayError(email_error, jQuery(this), quiz_form_id);
752
- result = false;
753
- }
754
- }
755
- var by_pass = true;
756
- if (qmn_quiz_data[quizID].timer_limit_val > 0 && qmn_quiz_data[quiz_id].hasOwnProperty('skip_validation_time_expire') && qmn_quiz_data[quiz_id].skip_validation_time_expire == 0) {
757
- by_pass = false;
758
- }
759
-
760
- if (localStorage.getItem('mlw_time_quiz' + quiz_id) === null || localStorage.getItem('mlw_time_quiz' + quiz_id) > 0.08 || by_pass === false) {
761
-
762
- if (jQuery(this).attr('class').indexOf('mlwRequiredNumber') > -1 && this.value === "" && +this.value != NaN) {
763
- qmnDisplayError(number_error, jQuery(this), quiz_form_id);
764
- result = false;
765
- }
766
- if (jQuery(this).attr('class').indexOf('mlwRequiredDate') > -1 && this.value === "") {
767
- qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
768
- result = false;
769
- }
770
- if (jQuery(this).attr('class').indexOf('mlwRequiredText') > -1 && jQuery.trim(this.value) === "") {
771
- qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
772
- result = false;
773
- }
774
- if (jQuery(this).attr('class').indexOf('mlwRequiredCaptcha') > -1 && this.value != mlw_code) {
775
- qmnDisplayError(incorrect_error, jQuery(this), quiz_form_id);
776
- result = false;
777
- }
778
- if (jQuery(this).attr('class').indexOf('mlwRequiredAccept') > -1 && !jQuery(this).prop('checked')) {
779
- qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
780
- result = false;
781
- }
782
- if (jQuery(this).attr('class').indexOf('mlwRequiredRadio') > -1) {
783
- check_val = jQuery(this).find('input:checked').val();
784
- if (check_val == "No Answer Provided" || check_val == "") {
785
- qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
786
- result = false;
787
- }
788
- }
789
- if (jQuery(this).attr('class').indexOf('mlwRequiredFileUpload') > -1) {
790
- var selected_file = jQuery(this).get(0).files.length;
791
- if (selected_file === 0) {
792
- qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
793
- result = false;
794
- }
795
- }
796
- if (jQuery(this).attr('class').indexOf('qsmRequiredSelect') > -1) {
797
- check_val = jQuery(this).val();
798
- if (check_val == "No Answer Provided" || check_val == "") {
799
- qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
800
- result = false;
801
- }
802
- }
803
- if (jQuery(this).attr('class').indexOf('mlwRequiredCheck') > -1) {
804
- if (!jQuery(this).find('input:checked').length) {
805
- qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
806
- result = false;
807
- }
808
- }
809
- //Google recaptcha validation
810
- if (jQuery(this).attr('class').indexOf('g-recaptcha-response') > -1) {
811
- if (grecaptcha.getResponse() == "") {
812
- alert('ReCaptcha is missing');
813
- result = false;
814
- }
815
- }
816
- }
817
- }
818
- });
819
- jQuery(document).trigger('qsm_after_validation', [element, quiz_form_id]);
820
- return result;
821
- }
822
-
823
- function getFormData($form) {
824
- var unindexed_array = $form.serializeArray();
825
- var indexed_array = {};
826
-
827
- jQuery.map(unindexed_array, function (n, i) {
828
- indexed_array[n['name']] = n['value'];
829
- });
830
-
831
- return indexed_array;
832
- }
833
-
834
- function qmnFormSubmit(quiz_form_id) {
835
-
836
- var quiz_id = +jQuery('#' + quiz_form_id).find('.qmn_quiz_id').val();
837
- var $container = jQuery('#' + quiz_form_id).closest('.qmn_quiz_container');
838
- var result = qmnValidation('#' + quiz_form_id + ' *', quiz_form_id);
839
-
840
- if (!result) { return result; }
841
-
842
- /**
843
  * Update Timer in MS
844
  */
845
-
846
- var timer_ms = jQuery('#' + quiz_form_id).find("input[name='timer_ms']").val();
847
- var new_timer_ms = qsmTimeInMS();
848
- jQuery('#' + quiz_form_id).find("input[name='timer_ms']").val(Math.abs(new_timer_ms - timer_ms));
849
-
850
- jQuery('.mlw_qmn_quiz input:radio').attr('disabled', false);
851
- jQuery('.mlw_qmn_quiz input:checkbox').attr('disabled', false);
852
- jQuery('.mlw_qmn_quiz select').attr('disabled', false);
853
- jQuery('.mlw_qmn_question_comment').attr('disabled', false);
854
- jQuery('.mlw_answer_open_text').attr('disabled', false);
855
-
856
- //Convert serialize data into index array
857
- var unindexed_array = jQuery('#' + quiz_form_id).serializeArray();
858
- var fd = new FormData();
859
- jQuery.each(unindexed_array, function (key, input) {
860
- fd.append(input.name, input.value);
861
- });
862
- fd.append("action", 'qmn_process_quiz');
863
- fd.append("currentuserTime", Math.round(new Date().getTime()/1000));
864
- fd.append("currentuserTimeZone",Intl.DateTimeFormat().resolvedOptions().timeZone);
865
-
866
-
867
- qsmEndTimeTakenTimer();
868
- if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
869
- QSMPageTimer.endPageTimer(quiz_id);
870
- }
871
- if (qmn_quiz_data[quiz_id].hasOwnProperty('timer_limit')) {
872
- QSM.endTimer(quiz_id);
873
- }
874
- jQuery(document).trigger('qsm_before_quiz_submit', [quiz_form_id]);
875
- jQuery('#' + quiz_form_id + ' input[type=submit]').attr('disabled', 'disabled');
876
- qsmDisplayLoading($container, quiz_id);
877
- // console.log( 'submitted data:' + unindexed_array );
878
- jQuery.ajax({
879
- url: qmn_ajax_object.ajaxurl,
880
- data: fd,
881
- contentType: false,
882
- processData: false,
883
- type: 'POST',
884
- success: function (response) {
885
- response=JSON.parse(response);
886
- if (window.qsm_results_data === undefined) {
887
- window.qsm_results_data = new Object();
888
- }
889
- window.qsm_results_data[quizID]={
890
- 'save_response' : response.result_status['save_response'],
891
- 'id' : response.result_status['id']
892
- };
893
-
894
- if(response.quizExpired){
895
- MicroModal.show('modal-4');
896
- return false;
897
- }else{
898
- qmnDisplayResults(response, quiz_form_id, $container);
899
- jQuery(document).trigger('qsm_after_quiz_submit_load_chart');
900
- jQuery(document).trigger('qsm_after_quiz_submit', [quiz_form_id]);
901
- }
902
- }
903
- });
904
-
905
- return false;
906
- }
907
-
908
- function qsmDisplayLoading($container, quiz_id) {
909
- var loader_html = '<div class="qsm_quiz_processing_box">';
910
- loader_html += '<div class="qsm-spinner-loader qsm_quiz_processing_loader"></div>';
911
- if (qmn_quiz_data[quiz_id].hasOwnProperty('quiz_processing_message') && qmn_quiz_data[quiz_id].quiz_processing_message != '') {
912
- loader_html += '<div class="qsm_quiz_processing_message">'+qmn_quiz_data[quiz_id].quiz_processing_message+'</div>';
913
- }
914
- loader_html += '</div>';
915
- $container.empty();
916
- $container.append(loader_html);
917
- qsmScrollTo($container);
918
- }
919
-
920
- function qmnDisplayResults(results, quiz_form_id, $container) {
921
- $container.empty();
922
- jQuery(document).trigger('qsm_before_display_result', [results, quiz_form_id, $container]);
923
- if (results.redirect) {
924
- window.location.replace(results.redirect);
925
- } else {
926
- $container.append('<div class="qmn_results_page"></div>');
927
- $container.find('.qmn_results_page').html(results.display);
928
- qsmScrollTo($container);
929
- // run MathJax on the new content
930
- MathJax.typesetPromise();
931
- // Fires after result is populates via ajax
932
- jQuery(document).trigger('qsm_after_display_result', [results, quiz_form_id, $container]);
933
- }
934
- }
935
-
936
- function qmnInit() {
937
- if (typeof qmn_quiz_data != 'undefined' && qmn_quiz_data) {
938
- let key = Object.keys(qmn_quiz_data)[0];
939
- if (qmn_quiz_data[key].ajax_show_correct === '1') {
940
- jQuery('#quizForm' + qmn_quiz_data[key].quiz_id + ' .qmn_quiz_radio').change(function () {
941
- var chosen_answer = jQuery(this).val();
942
- var question_id = jQuery(this).attr('name').replace(/question/i, '');
943
- var chosen_id = jQuery(this).attr('id');
944
- jQuery.each(qmn_quiz_data[key].question_list, function (i, value) {
945
- if (question_id == value.question_id) {
946
- jQuery.each(value.answers, function (j, answer) {
947
- if (answer[0] === chosen_answer) {
948
- if (answer[2] !== 1) {
949
- jQuery('#' + chosen_id).parent().addClass("qmn_incorrect_answer");
950
- }
951
- }
952
- if (answer[2] === 1) {
953
- jQuery(':radio[name=question' + question_id + '][value="' + answer[0] + '"]').parent().addClass("qmn_correct_answer");
954
- }
955
- });
956
- }
957
- });
958
- });
959
- }
960
-
961
- if (qmn_quiz_data[key].disable_answer === '1') {
962
-
963
- jQuery('#quizForm' + qmn_quiz_data[key].quiz_id + ' .qmn_quiz_radio').change(function () {
964
- var radio_group = jQuery(this).attr('name');
965
- jQuery('input[type=radio][name=' + radio_group + ']').prop('disabled', true);
966
- let radio_value =jQuery(this).val();
967
- let disableAnswer = {};
968
- if ( localStorage.getItem( "disable_answer" ) ){
969
- disableAnswer = JSON.parse(localStorage.getItem("disable_answer"));
970
- }
971
- if (!disableAnswer[key]){
972
- disableAnswer[key]=[];
973
- }
974
- let disabledQuestions = disableAnswer[key].map(element => element[0]);
975
- if (! disabledQuestions.includes(radio_group) ){
976
- disableAnswer[key].push([radio_group, radio_value]);
977
- }
978
- localStorage.setItem("disable_answer",JSON.stringify(disableAnswer));
979
- });
980
-
981
- if(localStorage.getItem("disable_answer")){
982
- let disabledAnswer = JSON.parse(localStorage.getItem("disable_answer"));
983
- if(disabledAnswer[key]){
984
- disabledAnswer[key].forEach(element => {
985
- let element1=element[1].replaceAll(' ','-');
986
- jQuery('#'+element[0]+'-'+element1+' input').prop('checked', true).trigger('change');
987
- });
988
- }
989
- }
990
- jQuery(document).on('qsm_after_quiz_submit',function(event, quiz_form_id ){
991
- event.preventDefault();
992
- if(localStorage.getItem("disable_answer")){
993
- let disabledAnswer2 = JSON.parse(localStorage.getItem("disable_answer"));
994
- if(disabledAnswer2[key]){
995
- delete disabledAnswer2[key];
996
- localStorage.setItem("disable_answer",JSON.stringify(disabledAnswer2)); }
997
- }
998
- });
999
- }
1000
-
1001
- if (qmn_quiz_data[key].hasOwnProperty('pagination')) {
1002
- qmnInitPagination(qmn_quiz_data[key].quiz_id);
1003
- }
1004
- }
1005
- }
1006
-
1007
- //Function to validate the answers provided in quiz
1008
- function qmnValidatePage(quiz_form_id) {
1009
- var result = qmnValidation('#' + quiz_form_id + ' .quiz_section:visible *', quiz_form_id);
1010
- return result;
1011
- }
1012
-
1013
- //Function to advance quiz to next page
1014
- function qmnNextSlide(pagination, go_to_top, quiz_form_id) {
1015
- jQuery(document).trigger('qsm_next_button_click_before', [quiz_form_id]);
1016
- var quiz_id = +jQuery(quiz_form_id).find('.qmn_quiz_id').val();
1017
- var $container = jQuery(quiz_form_id).closest('.qmn_quiz_container');
1018
- var slide_number = +$container.find('.slide_number_hidden').val();
1019
- var page_number = +$container.find('.current_page_hidden').val();
1020
- var section_totals = +$container.find('.total_sections_hidden').val();
1021
- if (pagination == 1) {
1022
- section_totals = section_totals - 1;
1023
- }
1024
- var total_pages = $container.find('.total_pages_hidden').val();
1025
-
1026
- jQuery(quiz_form_id + " .qsm-auto-page-row").hide();
1027
- if (page_number >= total_pages) {
1028
- alert('Next page not found.');
1029
- $container.find(".mlw_next").hide();
1030
- jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_end").show();
1031
- return true;
1032
- }
1033
- if (slide_number == 0 && page_number == 0) {
1034
- jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_begin").show();
1035
- $container.find(".mlw_previous").hide();
1036
- $container.find('.current_page_hidden').val('1');
1037
- } else if (total_pages == parseInt(page_number) + 1) { //Last page
1038
- $container.find(".mlw_next").hide();
1039
- jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_end").show();
1040
- $container.find('.slide_number_hidden').val(parseInt(slide_number) + 1);
1041
- $container.find('.current_page_hidden').val(parseInt(page_number) + 1);
1042
- $container.find(".mlw_previous").show();
1043
- $container.find('.g-recaptcha').show();
1044
- } else if (slide_number >= 0 && page_number >= 1) {
1045
- if (total_pages == parseInt(page_number) + 2) { // if last page empty
1046
- if (jQuery(quiz_form_id + " .qsm-auto-page-row.empty_quiz_end").length) {
1047
- submit_button = jQuery(quiz_form_id + " .qsm-auto-page-row.empty_quiz_end").html();
1048
- jQuery(quiz_form_id + " .qsm-auto-page-row.empty_quiz_end").show();
1049
- $container.find(".mlw_next").hide();
1050
- $container.find('.g-recaptcha').show();
1051
- }
1052
- }
1053
- $container.find('.qsm-auto-page-row.qsm-apc-' + page_number).show();
1054
- $container.find('.slide_number_hidden').val(parseInt(slide_number) + 1);
1055
- $container.find('.current_page_hidden').val(parseInt(page_number) + 1);
1056
- $container.find(".mlw_previous").show();
1057
- }
1058
- if (jQuery(quiz_form_id + " .quiz_section.quiz_end").is(':visible')) {
1059
- var button_width = jQuery(quiz_form_id + ' .qsm-submit-btn').width();
1060
- var progress_width = jQuery(quiz_form_id).parent().find('.qmn_pagination').width();
1061
- jQuery(quiz_form_id).parent().find('.qmn_pagination').css('width', progress_width - button_width - 40);
1062
- } else {
1063
- jQuery(quiz_form_id).parent().find('.qmn_pagination').css('width', '100%');
1064
- }
1065
- if (go_to_top == 1 && qmn_quiz_data[quiz_id].disable_scroll_next_previous_click != 1) {
1066
- qsmScrollTo($container);
1067
- }
1068
- //Show the page counts
1069
- if (page_number > 0 && jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').length > 0) {
1070
- var actual_pages = total_pages - 2;
1071
- if (page_number <= actual_pages) {
1072
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').text('').text(page_number + qmn_ajax_object.out_of_text + actual_pages);
1073
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').show();
1074
- } else {
1075
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1076
- }
1077
- } else {
1078
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1079
- }
1080
- qmnInitProgressbarOnClick(quiz_id, page_number, total_pages);
1081
- jQuery(document).trigger('qsm_auto_next_button_click_after', [quiz_form_id]);
1082
- }
1083
-
1084
- function qmnPrevSlide(pagination, go_to_top, quiz_form_id) {
1085
- jQuery(document).trigger('qsm_previous_button_click_before', [quiz_form_id]);
1086
- var quiz_id = +jQuery(quiz_form_id).find('.qmn_quiz_id').val();
1087
- var $container = jQuery(quiz_form_id).closest('.qmn_quiz_container');
1088
- var slide_number = +$container.find('.slide_number_hidden').val();
1089
- var previous = +$container.find('.previous_amount_hidden').val();
1090
- var section_totals = +$container.find('.total_sections_hidden').val();
1091
- var page_number = +$container.find('.current_page_hidden').val();
1092
- var total_pages = $container.find('.total_pages_hidden').val();
1093
- jQuery(quiz_form_id + " .qsm-auto-page-row").hide();
1094
- jQuery(quiz_form_id + " .g-recaptcha").hide();
1095
- var slide_original_val = parseInt(slide_number) - 1;
1096
- if (slide_original_val == 0) {
1097
- $container.find(".mlw_next").show();
1098
- jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_begin").show();
1099
- $container.find('.slide_number_hidden').val(slide_original_val);
1100
- $container.find('.current_page_hidden').val(parseInt(page_number) - 1);
1101
- $container.find(".mlw_previous").hide();
1102
- } else {
1103
- $container.find('.qsm-auto-page-row.qsm-apc-' + slide_original_val).show();
1104
- $container.find('.slide_number_hidden').val(slide_original_val);
1105
- $container.find('.current_page_hidden').val(parseInt(page_number) - 1);
1106
- $container.find(".mlw_next").show();
1107
- }
1108
- if (go_to_top == 1 && qmn_quiz_data[quiz_id].disable_scroll_next_previous_click != 1) {
1109
- qsmScrollTo($container);
1110
- }
1111
- if (page_number > 0 && jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').length > 0) {
1112
- var actual_pages = total_pages - 2;
1113
- if (slide_original_val <= actual_pages) {
1114
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').text('').text(slide_original_val + qmn_ajax_object.out_of_text + actual_pages);
1115
- if (slide_original_val == 0) {
1116
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1117
- } else {
1118
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').show();
1119
- }
1120
- } else {
1121
- jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1122
- }
1123
- }
1124
- jQuery(quiz_form_id).parent().find('.qmn_pagination').css('width', '100%');
1125
- qmnInitProgressbarOnClick(quiz_id, slide_original_val, total_pages);
1126
- jQuery(document).trigger('qsm_auto_previous_button_click_after', [quiz_form_id]);
1127
- }
1128
-
1129
- /**
1130
- * @since 6.4.11
1131
- * @param {int} quiz_id
1132
- * @param {int} page_number
1133
- * @param {int} total_page_number
1134
- * @returns Change progress bar on next and previous button click
1135
- */
1136
- function qmnInitProgressbarOnClick(quiz_id, page_number, total_page_number) {
1137
- if ('1' == qmn_quiz_data[quiz_id].progress_bar) {
1138
- var qmn_total_questions = qmn_quiz_data[quiz_id].pagination.total_questions;
1139
- var pagination = qmn_quiz_data[quiz_id].pagination.amount;
1140
- total_page_number = Math.ceil(qmn_total_questions / pagination);
1141
- if (!jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').find('.empty_quiz_end').length) {
1142
- total_page_number = total_page_number + 1; //Increase for quiz end section
1143
- }
1144
- var animate_value = page_number / total_page_number;
1145
- if (animate_value <= 1) {
1146
- qmn_quiz_data[quiz_id].bar.animate(animate_value);
1147
- var old_text = jQuery('#qsm_progress_bar_' + quiz_id).find('.progressbar-text').text().replace(' %', '');
1148
- var new_text = Math.round(animate_value * 100);
1149
- jQuery({
1150
- Counter: old_text
1151
- }).animate({
1152
- Counter: new_text
1153
- }, {
1154
- duration: 1000,
1155
- easing: 'swing',
1156
- step: function () {
1157
- jQuery('#qsm_progress_bar_' + quiz_id).find('.progressbar-text').text(Math.round(this.Counter) + ' %');
1158
- }
1159
- });
1160
- }
1161
- }
1162
- }
1163
-
1164
- function qmnUpdatePageNumber(amount, quiz_form_id) {
1165
- var current_page = +jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.current_page_hidden').val();
1166
- var total_pages = jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.total_pages_hidden').val();
1167
- current_page += amount;
1168
- //jQuery( quiz_form_id ).siblings( '.qmn_pagination' ).find( " .qmn_page_counter_message" ).text( current_page + "/" + total_pages );
1169
- }
1170
-
1171
- function qmnInitPagination(quiz_id) {
1172
- var qmn_section_total = +qmn_quiz_data[quiz_id].pagination.total_questions;
1173
- var qmn_total_pages = Math.ceil(qmn_section_total / +qmn_quiz_data[quiz_id].pagination.amount);
1174
-
1175
- qmn_total_pages = qmn_total_pages + 1; //quiz begin
1176
- qmn_total_pages = qmn_total_pages + 1; //quiz end
1177
-
1178
-
1179
- jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').append('<div class="qmn_pagination border margin-bottom"></div>');
1180
- jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').find('.qmn_pagination').append('<input type="hidden" value="0" name="slide_number" class="slide_number_hidden" />')
1181
- .append('<input type="hidden" value="0" name="current_page" class="current_page_hidden" />')
1182
- .append('<input type="hidden" value="' + qmn_total_pages + '" name="total_pages" class="total_pages_hidden" />')
1183
- .append('<input type="hidden" value="' + qmn_section_total + '" name="total_sections" class="total_sections_hidden" />')
1184
- .append('<input type="hidden" value="0" name="previous_amount" class="previous_amount_hidden" />')
1185
- .append('<a class="qmn_btn mlw_qmn_quiz_link mlw_previous" href="#">' + qmn_quiz_data[quiz_id].pagination.previous_text + '</a>')
1186
- .append('<span class="qmn_page_message"></span>')
1187
- .append('<div class="qmn_page_counter_message"></div>')
1188
- .append('<div class="qsm-progress-bar" id="qsm_progress_bar_' + quiz_id + '" style="display:none;"><div class="progressbar-text"></div></div>')
1189
- .append('<a class="qmn_btn mlw_qmn_quiz_link mlw_next" href="#">' + qmn_quiz_data[quiz_id].pagination.next_text + '</a>');
1190
-
1191
- if ('1' == qmn_quiz_data[quiz_id].progress_bar) {
1192
- jQuery(document).trigger('qsm_init_progressbar_before', [quiz_id, qmn_quiz_data]);
1193
- jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').find('.qsm-progress-bar').show();
1194
- qmn_quiz_data[quiz_id].bar = new ProgressBar.Line('#qsm_progress_bar_' + quiz_id, {
1195
- strokeWidth: 2,
1196
- easing: 'easeInOut',
1197
- duration: 500,
1198
- color: '#3498db',
1199
- trailColor: '#eee',
1200
- trailWidth: 1,
1201
- svgStyle: { width: '100%', height: '100%' },
1202
- text: {
1203
- style: {
1204
- // color: '#999',
1205
- position: 'absolute',
1206
- padding: 0,
1207
- margin: 0,
1208
- top: 0,
1209
- right: '10px',
1210
- 'font-size': '13px',
1211
- 'font-weight': 'bold',
1212
- transform: null
1213
- },
1214
- autoStyleContainer: false
1215
- },
1216
- from: { color: '#3498db' },
1217
- to: { color: '#ED6A5A' },
1218
- step: function (state, bar) {
1219
- }
1220
- });
1221
- jQuery(document).trigger('qsm_init_progressbar_after', [quiz_id, qmn_quiz_data]);
1222
- }
1223
-
1224
- jQuery(".mlw_next").click(function (event) {
1225
- event.preventDefault();
1226
- var quiz_id = +jQuery(this).closest('.qmn_quiz_container').find('.qmn_quiz_id').val();
1227
- jQuery(document).trigger('qsm_auto_next_button_click_before', [quiz_id]);
1228
- if (qmnValidatePage('quizForm' + quiz_id)) {
1229
- qmnNextSlide(qmn_quiz_data[quiz_id].pagination.amount, 1, '#quizForm' + quiz_id);
1230
- }
1231
- });
1232
-
1233
- jQuery(".mlw_previous").click(function (event) {
1234
- event.preventDefault();
1235
- var quiz_id = +jQuery(this).closest('.qmn_quiz_container').find('.qmn_quiz_id').val();
1236
- qmnPrevSlide(qmn_quiz_data[quiz_id].pagination.amount, 1, '#quizForm' + quiz_id);
1237
- });
1238
-
1239
- if (qmn_quiz_data[quiz_id].first_page) {
1240
- qmnNextSlide(1, 0, '#quizForm' + quiz_id);
1241
- } else {
1242
- qmnNextSlide(qmn_quiz_data[quiz_id].pagination.amount, 0, '#quizForm' + quiz_id);
1243
- }
1244
-
1245
- }
1246
-
1247
- function qmnSocialShare(network, mlw_qmn_social_text, mlw_qmn_title, facebook_id, share_url) {
1248
- var sTop = window.screen.height / 2 - (218);
1249
- var sLeft = window.screen.width / 2 - (313);
1250
- var sqShareOptions = "height=400,width=580,toolbar=0,status=0,location=0,menubar=0,directories=0,scrollbars=0,top=" + sTop + ",left=" + sLeft;
1251
- var pageUrl = window.location.href;
1252
- var pageUrlEncoded = encodeURIComponent(share_url);
1253
- var url = '';
1254
- if (network == 'facebook') {
1255
- url = "https://www.facebook.com/dialog/feed?" + "display=popup&" + "app_id=" + facebook_id +
1256
- "&" + "link=" + pageUrlEncoded + "&" + "name=" + encodeURIComponent(mlw_qmn_social_text) +
1257
- "&" + "description=";
1258
- }
1259
- if (network == 'twitter') {
1260
- url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(mlw_qmn_social_text);
1261
- }
1262
- window.open(url, "Share", sqShareOptions);
1263
- return false;
1264
- }
1265
-
1266
- jQuery(function () {
1267
- jQuery('.qmn_quiz_container').tooltip();
1268
-
1269
- jQuery('.qmn_quiz_container input').on('keypress', function (e) {
1270
- if (e.which === 13) {
1271
- e.preventDefault();
1272
- }
1273
- });
1274
-
1275
- jQuery(document).on('click', ".qsm-submit-btn", function (event) {
1276
- event.preventDefault();
1277
- var form = jQuery(this).closest('form')[0];
1278
- qmnFormSubmit(form.id);
1279
- });
1280
-
1281
- jQuery(document).on('click', '.btn-reload-quiz', function (e) {
1282
- e.preventDefault();
1283
- var quiz_id = jQuery(this).data('quiz_id');
1284
- var parent_div = jQuery(this).parents('.qsm-quiz-container');
1285
- qsmDisplayLoading(parent_div, quiz_id);
1286
- jQuery.ajax({
1287
- type: 'POST',
1288
- url: qmn_ajax_object.ajaxurl,
1289
- data: {
1290
- action: "qsm_get_quiz_to_reload",
1291
- quiz_id: quiz_id,
1292
- },
1293
- success: function (response) {
1294
- parent_div.replaceWith(response);
1295
- //Reload the timer and pagination
1296
- qmnDoInit();
1297
-
1298
- MathJax.typesetPromise();
1299
-
1300
- // trigger fired on successfull retake quiz
1301
- jQuery(document).trigger('qsm_retake_quiz', [quiz_id]);
1302
- },
1303
- error: function (errorThrown) {
1304
- console.log('error');
1305
- }
1306
- });
1307
- });
1308
-
1309
- jQuery(document).on('change', '.qmn_radio_answers input', function (e) {
1310
- var quizID = jQuery(this).parents('.qsm-quiz-container').find('.qmn_quiz_id').val();
1311
- if (qmn_quiz_data[quizID].enable_quick_result_mc == 1) {
1312
- var question_id = jQuery(this).attr('name').split('question')[1],
1313
- value = jQuery(this).val(),
1314
- $this = jQuery(this).parents('.quiz_section');
1315
- jQuery.ajax({
1316
- type: 'POST',
1317
- url: qmn_ajax_object.ajaxurl,
1318
- data: {
1319
- action: "qsm_get_question_quick_result",
1320
- question_id: question_id,
1321
- answer: value,
1322
- show_correct_info: qmn_quiz_data[quizID].enable_quick_correct_answer_info
1323
- },
1324
- success: function (response) {
1325
- var data = jQuery.parseJSON(response);
1326
- $this.find('.quick-question-res-p').remove();
1327
- $this.find('.qsm-inline-correct-info').remove();
1328
- if (data.success == 'correct') {
1329
- $this.append('<div style="color: green" class="quick-question-res-p">' + qmn_quiz_data[quizID].quick_result_correct_answer_text + '</div>')
1330
- $this.append('<div class="qsm-inline-correct-info">' + data.message + '</div>');
1331
- } else if (data.success == 'incorrect') {
1332
- $this.append('<div style="color: red" class="quick-question-res-p">' + qmn_quiz_data[quizID].quick_result_wrong_answer_text + '</div>')
1333
- $this.append('<div class="qsm-inline-correct-info">' + data.message + '</div>');
1334
- }
1335
- MathJax.typesetPromise();
1336
- },
1337
- error: function (errorThrown) {
1338
- alert(errorThrown);
1339
- }
1340
- });
1341
- }
1342
- });
1343
-
1344
- // Autocomplete off
1345
-
1346
- var quizID = jQuery('.qsm-quiz-container').find('.qmn_quiz_id').val();
1347
- var $quizForm = QSM.getQuizForm(quizID);
1348
- if (qmn_quiz_data[quizID].form_disable_autofill == 1) {
1349
- jQuery('#quizForm' + quizID).attr('autocomplete', 'off');
1350
- }
1351
-
1352
-
1353
-
1354
- // End Quiz If Wrong
1355
- jQuery(document).on('change ', '.qmn_radio_answers input , .qmn_check_answers input , .qsm_select', function (e) {
1356
- var quizID = jQuery(this).parents('.qsm-quiz-container').find('.qmn_quiz_id').val();
1357
- var $quizForm = QSM.getQuizForm(quizID);
1358
- if (qmn_quiz_data[quizID].end_quiz_if_wrong == 1) {
1359
- var question_id = jQuery(this).attr('name').split('question')[1],
1360
- value = jQuery(this).val(),
1361
- $this = jQuery(this).parents('.quiz_section');
1362
- jQuery.ajax({
1363
- type: 'POST',
1364
- url: qmn_ajax_object.ajaxurl,
1365
- data: {
1366
- action: "qsm_get_question_quick_result",
1367
- question_id: question_id,
1368
- answer: value,
1369
- show_correct_info: qmn_quiz_data[quizID].enable_quick_correct_answer_info
1370
- },
1371
- success: function (response) {
1372
- var data = jQuery.parseJSON(response);
1373
- $this.find('.quick-question-res-p').remove();
1374
- $this.find('.qsm-inline-correct-info').remove();
1375
- if (data.success == 'correct') {
1376
- } else if (data.success == 'incorrect') {
1377
- $this.append('<div style="color: red" class="quick-question-res-p">' + qmn_quiz_data[quizID].quick_result_wrong_answer_text + '</div>')
1378
- $this.append('<div class="qsm-inline-correct-info">' + data.message + '</div>');
1379
- setTimeout(function () {
1380
- $quizForm.closest('.qmn_quiz_container').find('.qsm-submit-btn').trigger('click');
1381
- }, 1000);
1382
- }
1383
- MathJax.typesetPromise();
1384
- },
1385
- error: function (errorThrown) {
1386
- alert(errorThrown);
1387
- }
1388
- });
1389
- }
1390
- });
1391
-
1392
- //Ajax upload file code
1393
- jQuery('.quiz_section .mlw_answer_file_upload').on('change', function () {
1394
- var $this = jQuery(this);
1395
- var hidden_val = jQuery(this).parent('.quiz_section').find('.mlw_file_upload_hidden_path').val();
1396
- var file_data = jQuery(this).prop('files')[0];
1397
- var form_data = new FormData();
1398
- form_data.append('file', file_data);
1399
- form_data.append('action', 'qsm_upload_image_fd_question');
1400
- var question_id = $this.parent('.quiz_section').find('.mlw_file_upload_hidden_value').attr("name").replace('question', '');
1401
- form_data.append('question_id', question_id);
1402
- $this.next('.loading-uploaded-file').show();
1403
- jQuery.ajax({
1404
- url: qmn_ajax_object.ajaxurl,
1405
- type: 'POST',
1406
- data: form_data,
1407
- cache: false,
1408
- contentType: false,
1409
- processData: false,
1410
- success: function (response) {
1411
- var obj = jQuery.parseJSON(response);
1412
- $this.next('.loading-uploaded-file').hide();
1413
- if (obj.type == 'success') {
1414
- $this.next().next('.remove-uploaded-file').show();
1415
- $this.next().next().next('.mlw_file_upload_hidden_value').val(obj.file_url);
1416
- $this.parent('.quiz_section').find('.mlw_file_upload_hidden_path').val(obj.file_path);
1417
- $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').hide();
1418
- } else {
1419
- $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').text('').text(obj.message);
1420
- $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').show();
1421
- $this.parent('.quiz_section').find('.mlw_answer_file_upload').val('');
1422
- }
1423
- // triggers after file uploads
1424
- jQuery(document).trigger('qsm_after_file_upload', [$this.parent(), obj]);
1425
- }
1426
- });
1427
- return false;
1428
- });
1429
-
1430
- //Ajax remove file code
1431
- jQuery('.quiz_section .remove-uploaded-file').on('click', function () {
1432
- var $this = jQuery(this);
1433
- var file_data = jQuery(this).parent('.quiz_section').find('.mlw_file_upload_hidden_path').val();
1434
- var form_data = new FormData();
1435
- form_data.append('action', 'qsm_remove_file_fd_question');
1436
- form_data.append('file_url', file_data);
1437
- jQuery.ajax({
1438
- url: qmn_ajax_object.ajaxurl,
1439
- type: 'POST',
1440
- data: form_data,
1441
- cache: false,
1442
- contentType: false,
1443
- processData: false,
1444
- success: function (response) {
1445
- var obj = jQuery.parseJSON(response);
1446
- if (obj.type == 'success') {
1447
- $this.hide();
1448
- $this.parent('.quiz_section').find('.mlw_file_upload_hidden_value').val('');
1449
- $this.parent('.quiz_section').find('.mlw_file_upload_hidden_path').val('');
1450
- $this.parent('.quiz_section').find('.mlw_answer_file_upload').val('');
1451
- $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').hide();
1452
- } else {
1453
- $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').text('').text(obj.message);
1454
- $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').show();
1455
- }
1456
- }
1457
- });
1458
- return false;
1459
- });
1460
-
1461
- //Deselect all answer on select
1462
- jQuery('.qsm-deselect-answer').click(function (e) {
1463
- e.preventDefault();
1464
- jQuery(this).parents('.quiz_section').find('input[type="radio"]').prop('checked', false);
1465
- jQuery(this).parents('.quiz_section').find('input[type="radio"][value="No Answer Provided"]').prop('checked', true);
1466
- jQuery(this).parents('.quiz_section').find('input[type="radio"][value=""]').prop('checked', true);
1467
- });
1468
-
1469
- //Submit the form on popup click
1470
- jQuery(document).on('click', '.submit-the-form', function (e) {
1471
- e.preventDefault();
1472
- // Triggger the click event on the quiz form's submit button.
1473
- jQuery('.qsm-submit-btn').trigger('click');
1474
- jQuery('#modal-3').removeClass('is-open');
1475
- });
1476
-
1477
- jQuery('.pagetime-goto-nextpage').click(function (e) {
1478
- e.preventDefault();
1479
- var quiz_id = jQuery(this).data('quiz_id');
1480
- QSM.nextPage(quiz_id);
1481
- var $container = jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container');
1482
- qsmScrollTo($container);
1483
- });
1484
-
1485
- jQuery(document).on('keyup', '.mlwPhoneNumber', function (e) {
1486
- this.value = this.value.replace(/[^- +()0-9\.]/g, '');
1487
- });
1488
-
1489
- jQuery(document).on('click', '.qsm_social_share_link', function (e) {
1490
- e.preventDefault();
1491
- var network = jQuery(this).attr('data-network');
1492
- var share_url = jQuery(this).attr('data-link');
1493
- var social_text = jQuery(this).attr('data-text');
1494
- var social_id = jQuery(this).attr('data-id');
1495
- var url = '';
1496
- if (network == 'facebook') {
1497
- url = "https://www.facebook.com/dialog/feed?" + "display=popup&" + "app_id=" + social_id +
1498
- "&" + "link=" + encodeURIComponent(share_url) + "&" + "name=" + social_text;
1499
- }
1500
- if (network == 'twitter') {
1501
- url = "https://twitter.com/intent/tweet?text=" + social_text;
1502
- }
1503
- var sTop = window.screen.height / 2 - (218);
1504
- var sLeft = window.screen.width / 2 - (313);
1505
- var sqShareOptions = "height=400,width=580,toolbar=0,status=0,location=0,menubar=0,directories=0,scrollbars=0,top=" + sTop + ",left=" + sLeft;
1506
- window.open(url, "Share", sqShareOptions);
1507
- return false;
1508
- });
1509
- });
1510
-
1511
- // captcha question type
1512
-
1513
- jQuery(document).ready(function() {
1514
- let captchaElement = jQuery('#mlw_code_captcha');
1515
- if (captchaElement.length !== 0){
1516
- var mlw_code = '';
1517
- var mlw_chars = '0123456789ABCDEFGHIJKL!@#$%^&*()MNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
1518
- var mlw_code_length = 5;
1519
- for (var i=0; i<mlw_code_length; i++) {
1520
- var rnum = Math.floor(Math.random() * mlw_chars.length);
1521
- mlw_code += mlw_chars.substring(rnum,rnum+1);
1522
- }
1523
- var mlw_captchaCTX = document.getElementById('mlw_captcha').getContext('2d');
1524
- mlw_captchaCTX.font = 'normal 24px Verdana';
1525
- mlw_captchaCTX.strokeStyle = '#000000';
1526
- mlw_captchaCTX.clearRect(0,0,100,50);
1527
- mlw_captchaCTX.strokeText(mlw_code,10,30,70);
1528
- mlw_captchaCTX.textBaseline = 'middle';
1529
- document.getElementById('mlw_code_captcha').value = mlw_code;
1530
- }
1531
- });
1532
-
1533
- var qsmTimerInterval = setInterval(qmnTimeTakenTimer, 1000);
1534
- var quizType = 'default';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  * being deprecated and replaced with rewritten newer functions
8
  **************************/
9
 
10
+ var QSM;
11
+ var QSMPageTimer;
12
+ (function ($) {
13
+ QSM = {
14
+ /**
15
+ * Initializes all quizzes or surveys on the page
16
+ */
17
+ init: function () {
18
+ // Makes sure we have quizzes on this page
19
+ if (typeof qmn_quiz_data != 'undefined' && qmn_quiz_data) {
20
+ // hide the recaptcha by default
21
+ $('.g-recaptcha').hide();
22
+ // Cycle through all quizzes
23
+ _.each(qmn_quiz_data, function (quiz) {
24
+ quizID = parseInt(quiz.quiz_id);
25
+ QSM.initPagination(quizID);
26
+
27
+ if (quiz.hasOwnProperty('pagination') || quiz.qpages.hasOwnProperty(2)) {
28
+ qsmEndTimeTakenTimer();
29
+ jQuery('#timer').val(0);
30
+ jQuery("input[name='timer_ms']").val(0);
31
+ quizType = 'paginated';
32
+ }
33
+
34
+ if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
35
+ qsmEndTimeTakenTimer();
36
+ jQuery('#timer').val(0);
37
+ jQuery("input[name='timer_ms']").val(0);
38
+ QSMPageTimer.endPageTimer(quizID, true);
39
+ }
40
+ if (quiz.hasOwnProperty('timer_limit') && 0 != quiz.timer_limit) {
41
+ qsmEndTimeTakenTimer();
42
+ jQuery('#timer').val(0);
43
+ jQuery("input[name='timer_ms']").val(0);
44
+ QSM.initTimer(quizID);
45
+ quizType = 'timer';
46
+ }
47
+ });
48
+ }
49
+ },
50
+
51
+ /**
52
+ * Sets up timer for a quiz
53
+ *
54
+ * @param int quizID The ID of the quiz
55
+ */
56
+ initTimer: function (quizID) {
57
+
58
+ jQuery(document).trigger('qsm_init_timer_before', [quizID]);
59
+
60
+ // Gets our form
61
+ var $quizForm = QSM.getQuizForm(quizID);
62
+
63
+ // Creates timer status key.
64
+ qmn_quiz_data[quizID].timerStatus = false;
65
+
66
+ // If we are using the newer pagination system...
67
+ if (0 < $quizForm.children('.qsm-page').length) {
68
+ // If there is a first page...
69
+ if (qmn_quiz_data[quizID].hasOwnProperty('first_page') && !qmn_quiz_data[quizID].first_page) {
70
+ QSM.activateTimer(quizID);
71
+ $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
72
+ }
73
+ // ...else, we must be using the questions per page option.
74
+ } else {
75
+ if (qmn_quiz_data[quizID].hasOwnProperty('pagination') && qmn_quiz_data[quizID].first_page) {
76
+ $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.mlw_next').on('click', function (event) {
77
+ event.preventDefault();
78
+ if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
79
+ var start_timer = parseInt(qmn_quiz_data[quizID].advanced_timer.start_timer_page);
80
+ if ($('#quizForm' + quizID).closest('.qmn_quiz_container').find('.qmn_pagination > .slide_number_hidden').val() == start_timer) {
81
+ QSM.activateTimer(quizID);
82
+ $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
83
+ }
84
+ } else {
85
+ if (!qmn_quiz_data[quizID].timerStatus && (0 == $('.quiz_begin:visible').length || (1 == $('.quiz_begin:visible').length && qmnValidatePage('quizForm' + quizID)))) {
86
+ QSM.activateTimer(quizID);
87
+ $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
88
+ }
89
+ }
90
+ });
91
+ } else {
92
+ QSM.activateTimer(quizID);
93
+ $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
94
+ }
95
+ }
96
+ jQuery(document).trigger('qsm_init_timer_after', [quizID]);
97
+ },
98
+ /**
99
+ * Starts the timer for the quiz.
100
+ *
101
+ * @param int quizID The ID of the quiz.
102
+ */
103
+ activateTimer: function (quizID) {
104
+ timer_ms = jQuery("input[name='timer_ms']").val();
105
+ if (timer_ms == 0) {
106
+ qsmTimerInterval = setInterval(qmnTimeTakenTimer, 1000);
107
+ jQuery("input[name='timer_ms']").each(function () {
108
+ var timems = qsmTimeInMS();
109
+ jQuery(this).val(timems);
110
+ });
111
+ }
112
+
113
+ jQuery(document).trigger('qsm_activate_time_before', [quizID, qmn_quiz_data]);
114
+ // Gets our form.
115
+ var $timer = QSM.getTimer(quizID);
116
+
117
+ // Sets up our variables.
118
+ qmn_quiz_data[quizID].timerStatus = true;
119
+ var seconds = 0;
120
+
121
+ // Calculates starting time.
122
+ var timerStarted = localStorage.getItem('mlw_started_quiz' + quizID);
123
+ var timerRemaning = localStorage.getItem('mlw_time_quiz' + quizID);
124
+ if ('yes' == timerStarted && 0 < timerRemaning) {
125
+ seconds = parseInt(timerRemaning);
126
+ } else {
127
+ seconds = parseFloat(qmn_quiz_data[quizID].timer_limit) * 60;
128
+ }
129
+ qmn_quiz_data[quizID].timerRemaning = seconds;
130
+
131
+ //hidden timer
132
+ jQuery(".hiddentimer").html(seconds);
133
+
134
+ // Makes the timer appear.
135
+ $timer.show();
136
+ $timer.text(QSM.secondsToTimer(seconds));
137
+
138
+ // Sets up timer interval.
139
+ if (!isNaN(qmn_quiz_data[quizID].timerRemaning)) {
140
+ clearInterval(qmn_quiz_data[quizID].timerInterval);
141
+ qmn_quiz_data[quizID].timerInterval = setInterval(QSM.timer, 1000, quizID);
142
+ }
143
+ jQuery(document).trigger('qsm_activate_time_after', [quizID, qmn_quiz_data]);
144
+ },
145
+ /**
146
+ * Reduces the timer by one second and checks if timer is 0
147
+ *
148
+ * @param int quizID The ID of the quiz.
149
+ */
150
+ timer: function (quizID) {
151
+ qmn_quiz_data[quizID].timerRemaning -= 1;
152
+ if (0 > qmn_quiz_data[quizID].timerRemaning) {
153
+ qmn_quiz_data[quizID].timerRemaning = 0;
154
+ }
155
+ var secondsRemaining = qmn_quiz_data[quizID].timerRemaning;
156
+ var display = QSM.secondsToTimer(secondsRemaining);
157
+ var systemTime=new Date().getTime()/1000;
158
+ systemTime=Math.round(systemTime);
159
+ if('1'===qmn_quiz_data[quizID].not_allow_after_expired_time && systemTime > qmn_quiz_data[quizID].scheduled_time_end ){
160
+ MicroModal.show('modal-4');
161
+ return false;
162
+ }
163
+ // Sets our local storage values for the timer being started and current timer value.
164
+ localStorage.setItem('mlw_time_quiz' + quizID, secondsRemaining);
165
+ localStorage.setItem('mlw_started_quiz' + quizID, "yes");
166
+
167
+ // Updates timer element and title on browser tab.
168
+ var $timer = QSM.getTimer(quizID);
169
+ $timer.text(display);
170
+ document.title = display + ' ' + qsmTitleText;
171
+
172
+ /*CUSTOM TIMER*/
173
+ if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer') && qmn_quiz_data[quizID].advanced_timer.timer_design == 'big_timer') {
174
+ $(".second.circle").parent('.mlw_quiz_form').addClass('qsm_big_timer');
175
+ $(".second.circle").show();
176
+ $(".second.circle strong").html(display);
177
+ var datashow = ($(".hiddentimer").html() - secondsRemaining) / $(".hiddentimer").html();
178
+ $(".second.circle").circleProgress({
179
+ startAngle: 11,
180
+ value: datashow,
181
+ animation: false,
182
+ fill: { gradient: ["#00bb40", "#00511c"] }
183
+ });
184
+ }
185
+
186
+ var $quizForm = QSM.getQuizForm(quizID);
187
+ var total_seconds = parseFloat(qmn_quiz_data[quizID].timer_limit) * 60;
188
+ var ninety_sec = total_seconds - (total_seconds * 90 / 100);
189
+ if (ninety_sec == secondsRemaining) {
190
+ $quizForm.closest('.qmn_quiz_container').find('.qsm_ninety_warning').fadeIn();
191
+ }
192
+
193
+ // If timer is run out, disable fields.
194
+ if (0 >= secondsRemaining) {
195
+ clearInterval(qmn_quiz_data[quizID].timerInterval);
196
+ $(".mlw_qmn_quiz input:radio").attr('disabled', true);
197
+ $(".mlw_qmn_quiz input:checkbox").attr('disabled', true);
198
+ $(".mlw_qmn_quiz select").attr('disabled', true);
199
+ $(".mlw_qmn_question_comment").attr('disabled', true);
200
+ $(".mlw_answer_open_text").attr('disabled', true);
201
+ $(".mlw_answer_number").attr('readonly', true);
202
+
203
+ $quizForm.closest('.qmn_quiz_container').addClass('qsm_timer_ended');
204
+ $quizForm.closest('.qmn_quiz_container').prepend('<p class="qmn_error_message" style="color: red;">Quiz time is over</p>');
205
+ if (qmn_quiz_data[quizID].enable_result_after_timer_end == 1) {
206
+ $quizForm.closest('.qmn_quiz_container').find('.qsm-submit-btn').trigger('click');
207
+ } else {
208
+ MicroModal.show('modal-3');
209
+ }
210
+ return;
211
+ }
212
+ },
213
+ /**
214
+ * Clears timer interval
215
+ *
216
+ * @param int quizID The ID of the quiz
217
+ */
218
+ endTimer: function (quizID) {
219
+ localStorage.setItem('mlw_time_quiz' + quizID, 'completed');
220
+ localStorage.setItem('mlw_started_quiz' + quizID, 'no');
221
+ document.title = qsmTitleText;
222
+ if (typeof qmn_quiz_data[quizID].timerInterval != 'undefined') {
223
+ clearInterval(qmn_quiz_data[quizID].timerInterval);
224
+ }
225
+ jQuery(document).trigger('qsm_end_timer', [quizID, qmn_quiz_data]);
226
+ },
227
+ /**
228
+ * Converts seconds to 00:00:00 format
229
+ *
230
+ * @param int seconds The number of seconds
231
+ * @return string A string in H:M:S format
232
+ */
233
+ secondsToTimer: function (seconds) {
234
+ var formattedTime = '';
235
+ seconds = parseInt(seconds);
236
+
237
+ // Prepares the hours part.
238
+ var hours = Math.floor(seconds / 3600);
239
+ if (0 === hours) {
240
+ formattedTime = '00:';
241
+ } else if (10 > hours) {
242
+ formattedTime = '0' + hours + ':';
243
+ } else {
244
+ formattedTime = hours + ':';
245
+ }
246
+
247
+ // Prepares the minutes part.
248
+ var minutes = Math.floor((seconds % 3600) / 60);
249
+ if (0 === minutes) {
250
+ formattedTime = formattedTime + '00:';
251
+ } else if (10 > minutes) {
252
+ formattedTime = formattedTime + '0' + minutes + ':';
253
+ } else {
254
+ formattedTime = formattedTime + minutes + ':';
255
+ }
256
+
257
+ // Prepares the seconds part.
258
+ var remainder = Math.floor((seconds % 60));
259
+ if (0 === remainder) {
260
+ formattedTime = formattedTime + '00';
261
+ } else if (10 > remainder) {
262
+ formattedTime = formattedTime + '0' + remainder;
263
+ } else {
264
+ formattedTime = formattedTime + remainder;
265
+ }
266
+ return formattedTime;
267
+ },
268
+ /**
269
+ * Gets the jQuery object for the timer
270
+ */
271
+ getTimer: function (quizID) {
272
+ var $quizForm = QSM.getQuizForm(quizID);
273
+ return $quizForm.children('.mlw_qmn_timer');
274
+ },
275
+
276
+ /**
277
+ * Sets up pagination for a quiz
278
+ *
279
+ * @param int quizID The ID of the quiz.
280
+ */
281
+ initPagination: function (quizID) {
282
+ var $quizForm = QSM.getQuizForm(quizID);
283
+
284
+
285
+ /**
286
+ *
287
+ * CHecking if the quiz is random
288
+ */
289
+ $is_random = $('.qmn_quiz_container').hasClass('random');
290
+ if($is_random){
291
+ QSM.goToPage(quizID, 1);
292
+ }
293
+ else if (0 < $quizForm.children('.qsm-page').length) {
294
+ $quizForm.children('.qsm-page').hide();
295
+ template = wp.template('qsm-pagination-' + quizID);
296
+ $quizForm.append(template());
297
+ if ($quizForm.find('.qsm-pagination > .current_page_hidden').length == 0) {
298
+ $quizForm.find('.qsm-pagination').append('<input type="hidden" value="0" name="current_page" class="current_page_hidden" />');
299
+ }
300
+ if ('1' == qmn_quiz_data[quizID].progress_bar) {
301
+ jQuery(document).trigger('qsm_init_progressbar_before', [quizID, qmn_quiz_data]);
302
+ $('#quizForm' + quizID).find('.qsm-progress-bar').show();
303
+ qmn_quiz_data[quizID].bar = new ProgressBar.Line('#quizForm' + quizID + ' .qsm-progress-bar', {
304
+ strokeWidth: 2,
305
+ easing: 'easeInOut',
306
+ duration: 1400,
307
+ color: '#3498db',
308
+ trailColor: '#eee',
309
+ trailWidth: 1,
310
+ svgStyle: { width: '100%', height: '100%' },
311
+ text: {
312
+ style: {
313
+ // color: '#999',
314
+ position: 'absolute',
315
+ padding: 0,
316
+ margin: 0,
317
+ top: 0,
318
+ right: '10px',
319
+ 'font-size': '13px',
320
+ 'font-weight': 'bold',
321
+ transform: null
322
+ },
323
+ autoStyleContainer: false
324
+ },
325
+ from: { color: '#3498db' },
326
+ to: { color: '#ED6A5A' },
327
+ step: function (state, bar) {
328
+ //bar.setText(Math.round(bar.value() * 100) + ' %');
329
+ }
330
+ });
331
+ jQuery(document).trigger('qsm_init_progressbar_after', [quizID, qmn_quiz_data]);
332
+ }
333
+ QSM.goToPage(quizID, 1);
334
+
335
+ $quizForm.find('.qsm-pagination .qsm-next').on('click', function (event) {
336
+ jQuery(document).trigger('qsm_next_button_click_before', [quizID]);
337
+ event.preventDefault();
338
+ QSM.nextPage(quizID);
339
+ var $container = jQuery('#quizForm' + quizID).closest('.qmn_quiz_container');
340
+ if (qmn_quiz_data[quizID].disable_scroll_next_previous_click != 1) {
341
+ qsmScrollTo($container);
342
+ }
343
+ jQuery(document).trigger('qsm_next_button_click_after', [quizID]);
344
+ });
345
+ $quizForm.find('.qsm-pagination .qsm-previous').on('click', function (event) {
346
+ jQuery(document).trigger('qsm_previous_button_click_before', [quizID]);
347
+ event.preventDefault();
348
+ QSM.prevPage(quizID);
349
+ var $container = jQuery('#quizForm' + quizID).closest('.qmn_quiz_container');
350
+ if (qmn_quiz_data[quizID].disable_scroll_next_previous_click != 1) {
351
+ qsmScrollTo($container);
352
+ }
353
+ jQuery(document).trigger('qsm_previous_button_click_after', [quizID]);
354
+ });
355
+ }
356
+ },
357
+ /**
358
+ * Navigates quiz to specific page
359
+ *
360
+ * @param int pageNumber The number of the page
361
+ */
362
+ goToPage: function (quizID, pageNumber) {
363
+ jQuery(document).trigger('qsm_go_to_page_before', [quizID, pageNumber]);
364
+ var $quizForm = QSM.getQuizForm(quizID);
365
+ var $pages = $quizForm.children('.qsm-page');
366
+ var $currentPage = $quizForm.children('.qsm-page:nth-of-type(' + pageNumber + ')');
367
+ $pages.hide();
368
+ $currentPage.show();
369
+
370
+ if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
371
+ QSMPageTimer.endPageTimer(quizID);
372
+ QSMPageTimer.initPageTimer(quizID, $currentPage);
373
+ }
374
+
375
+ $quizForm.find('.current_page_hidden').val(pageNumber - 1);
376
+ $quizForm.find('.qsm-previous').hide();
377
+ $quizForm.find('.qsm-next').hide();
378
+ $quizForm.find('.qsm-submit-btn').hide();
379
+ $quizForm.find('.g-recaptcha').hide();
380
+ if (pageNumber < $pages.length) {
381
+
382
+ $quizForm.find('.qsm-next').show();
383
+ } else {
384
+ $quizForm.find('.qsm-submit-btn').show();
385
+ $quizForm.find('.g-recaptcha').show();
386
+ }
387
+ if (1 < pageNumber) {
388
+ $quizForm.find('.qsm-previous').show();
389
+ }
390
+ if (1 == $currentPage.data('prevbtn')) {
391
+ $quizForm.find('.qsm-previous').hide();
392
+ }
393
+ if ('1' == qmn_quiz_data[quizID].disable_first_page) {
394
+ if(pageNumber == 1){
395
+ $quizForm.find(".quiz_begin").hide();
396
+ $quizForm.find(".mlw_previous").hide();
397
+ $quizForm.find('.qsm-page-' + (parseInt(pageNumber))).show();
398
+ }
399
+ }
400
+ if ('1' == qmn_quiz_data[quizID].progress_bar) {
401
+ var current_page = jQuery('#quizForm' + quizID).find('.current_page_hidden').val();
402
+ var total_page_length = $pages.length - 1;
403
+ if (qmn_quiz_data[quizID].contact_info_location == 0) {
404
+ //Do nothing.
405
+ } else if (qmn_quiz_data[quizID].contact_info_location == 1) {
406
+ if ($quizForm.children('.qsm-page').find('.qsm_contact_div ').length > 0) {
407
+ //total_page_length = total_page_length - 1;
408
+ }
409
+ }
410
+ var animate_value = current_page / total_page_length;
411
+ if (animate_value <= 1) {
412
+ qmn_quiz_data[quizID].bar.animate(animate_value);
413
+ var old_text = jQuery('#quizForm' + quizID).find('.progressbar-text').text().replace(' %', '');
414
+ var new_text = Math.round(animate_value * 100);
415
+ jQuery({
416
+ Counter: old_text
417
+ }).animate({
418
+ Counter: new_text
419
+ }, {
420
+ duration: 1000,
421
+ easing: 'swing',
422
+ step: function () {
423
+ jQuery('#quizForm' + quizID).find('.progressbar-text').text(Math.round(this.Counter) + ' %');
424
+ }
425
+ });
426
+ }
427
+ }
428
+ QSM.savePage(quizID, pageNumber);
429
+ jQuery(document).trigger('qsm_go_to_page_after', [quizID, pageNumber]);
430
+ },
431
+ /**
432
+ * Moves forward or backwards through the pages
433
+ *
434
+ * @param int quizID The ID of the quiz
435
+ * @param int difference The number of pages to forward or back
436
+ */
437
+ changePage: function (quizID, difference) {
438
+ var page = QSM.getPage(quizID);
439
+ if(qmn_quiz_data[quizID].hasOwnProperty('first_page') && qmn_quiz_data[quizID].first_page){
440
+ if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
441
+ var start_timer = parseInt(qmn_quiz_data[quizID].advanced_timer.start_timer_page);
442
+ if ( page == start_timer ) { // check current page
443
+ QSM.activateTimer(quizID);
444
+ $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
445
+ }
446
+ } else {
447
+ if (!qmn_quiz_data[quizID].timerStatus ) {
448
+ QSM.activateTimer(quizID);
449
+ $('#quizForm' + quizID).closest('.qmn_quiz_container').find('.stoptimer-p').show();
450
+ }
451
+ }
452
+
453
+ }
454
+ page += difference;
455
+ QSM.goToPage(quizID, page);
456
+ },
457
+ nextPage: function (quizID) {
458
+ if (qmnValidatePage('quizForm' + quizID)) {
459
+ QSM.changePage(quizID, 1);
460
+ }
461
+ },
462
+ prevPage: function (quizID) {
463
+ QSM.changePage(quizID, -1);
464
+ },
465
+ savePage: function (quizID, pageNumber) {
466
+ sessionStorage.setItem('quiz' + quizID + 'page', pageNumber);
467
+ },
468
+ getPage: function (quizID) {
469
+ pageNumber = parseInt(sessionStorage.getItem('quiz' + quizID + 'page'));
470
+ if (isNaN(pageNumber) || null == pageNumber) {
471
+ pageNumber = 1;
472
+ }
473
+ return pageNumber;
474
+ },
475
+ /**
476
+ * Scrolls to the top of supplied element
477
+ *
478
+ * @param jQueryObject The jQuery version of an element. i.e. $('#quizForm3')
479
+ */
480
+ scrollTo: function ($element) {
481
+ jQuery('html, body').animate(
482
+ {
483
+ scrollTop: $element.offset().top - 150
484
+ },
485
+ 1000);
486
+ },
487
+ /**
488
+ * Gets the jQuery object of the quiz form
489
+ */
490
+ getQuizForm: function (quizID) {
491
+ return $('#quizForm' + quizID);
492
+ }
493
+ };
494
+
495
+ QSMPageTimer = {
496
+ /**
497
+ * Init Page Timer
498
+ */
499
+ initPageTimer: function (quizID, $currentpage) {
500
+ jQuery(document).trigger('qsm_init_page_timer_before', [quizID, $currentpage]);
501
+ var $quizForm = QSM.getQuizForm(quizID);
502
+ var pid = $currentpage.data('pid');
503
+ if (undefined != pid) {
504
+ var $qpages = qmn_quiz_data[quizID].qpages;
505
+ var $curr_page_opt = $qpages[pid];
506
+ if ($curr_page_opt.hasOwnProperty('pagetimer') && 0 != $curr_page_opt.pagetimer) {
507
+ var $timer_box = $currentpage.find('.qsm-pagetimer');
508
+ var seconds = 0;
509
+ var timerStarted = localStorage.getItem('mlw_started_q' + quizID + '_page' + pid);
510
+ var timerStoped = localStorage.getItem('mlw_stoped_q' + quizID + '_page' + pid);
511
+ var timerRemaning = localStorage.getItem('mlw_time_q' + quizID + '_page' + pid);
512
+ if (timerStoped != 'undefined' && timerStoped > 0) {
513
+ seconds = timerStoped;
514
+ } else {
515
+ if ('yes' == timerStarted) {
516
+ if (0 < timerRemaning) {
517
+ seconds = parseInt(timerRemaning);
518
+ }
519
+ } else {
520
+ seconds = parseFloat($curr_page_opt.pagetimer) * 60;
521
+ }
522
+ }
523
+ qmn_quiz_data[quizID].qpages[pid].timerRemaning = seconds;
524
+ /* Makes the timer appear. */
525
+ $timer_box.show();
526
+ $timer_box.text(QSMPageTimer.secondsToTimer(seconds));
527
+ /* Sets up timer interval. */
528
+ qmn_quiz_data[quizID].qpages[pid].timerInterval = setInterval(QSMPageTimer.timer, 1000, quizID, pid, $timer_box);
529
+ }
530
+ $currentpage.find('.page_intro_wrapper video').each(function () {
531
+ var $this = jQuery(this);
532
+ var src = $this.find('source').attr('src');
533
+ $this.attr('src', src)
534
+ $this.load();
535
+ $this.get(0).play();
536
+ });
537
+ }
538
+ jQuery(document).trigger('qsm_init_page_timer_after', [quizID, $currentpage]);
539
+ },
540
+ /**
541
+ * Reduces the timer by one second and checks if timer is 0
542
+ * @param int quizID The ID of the quiz.
543
+ */
544
+ timer: function (quizID, pid, $timer_box) {
545
+ var $quizForm = QSM.getQuizForm(quizID);
546
+ var $page = qmn_quiz_data[quizID].qpages[pid];
547
+ qmn_quiz_data[quizID].qpages[pid].timerRemaning -= 1;
548
+ if (0 > qmn_quiz_data[quizID].qpages[pid].timerRemaning) {
549
+ qmn_quiz_data[quizID].qpages[pid].timerRemaning = 0;
550
+ }
551
+ var total_seconds = parseFloat($page.pagetimer) * 60;
552
+ var secondsRemaining = qmn_quiz_data[quizID].qpages[pid].timerRemaning;
553
+ var display = QSMPageTimer.secondsToTimer(secondsRemaining);
554
+ $timer_box.text(display);
555
+ var pageTimeTaken = total_seconds - secondsRemaining;
556
+ jQuery('#pagetime_' + pid).val(pageTimeTaken);
557
+ /* Sets our local storage values for the timer being started and current timer value. */
558
+ localStorage.setItem('mlw_started_q' + quizID + '_page' + pid, "yes");
559
+ localStorage.setItem('mlw_time_q' + quizID + '_page' + pid, secondsRemaining);
560
+ if ($page.hasOwnProperty('pagetimer_warning') && 0 != $page.pagetimer_warning) {
561
+ var page_warning_sec = parseFloat($page.pagetimer_warning) * 60;
562
+ if (page_warning_sec == secondsRemaining) {
563
+ $timer_box.parents('.qsm-page').find('.qsm-pagetimer-warning').fadeIn();
564
+ }
565
+ }
566
+ /* If timer is run out, disable fields. */
567
+ if (0 >= secondsRemaining) {
568
+ clearInterval(qmn_quiz_data[quizID].qpages[pid].timerInterval);
569
+
570
+ $(".qsm-page:visible input:radio").attr('disabled', true);
571
+ $(".qsm-page:visible input:checkbox").attr('disabled', true);
572
+ $(".qsm-page:visible select").attr('disabled', true);
573
+ $(".qsm-page:visible .mlw_qmn_question_comment").attr('disabled', true);
574
+ $(".qsm-page:visible .mlw_answer_open_text").attr('disabled', true);
575
+ $(".qsm-page:visible .mlw_answer_number").attr('disabled', true);
576
+
577
+ QSMPageTimer.endPageTimer(quizID);
578
+ MicroModal.show('modal-page-1');
579
+ return;
580
+ }
581
+ },
582
+ /**
583
+ * Clears timer interval
584
+ * @param int quizID The ID of the quiz
585
+ */
586
+ endPageTimer: function (quizID, clearStorage = false) {
587
+ jQuery.each(qmn_quiz_data[quizID].qpages, function (i, value) {
588
+ if (value.hasOwnProperty('pagetimer') && 0 != value.pagetimer) {
589
+ if (clearStorage) {
590
+ localStorage.removeItem('mlw_started_q' + quizID + '_page' + value.id);
591
+ localStorage.removeItem('mlw_stoped_q' + quizID + '_page' + value.id);
592
+ localStorage.removeItem('mlw_time_q' + quizID + '_page' + value.id);
593
+ }
594
+ var secondsRemaining = qmn_quiz_data[quizID].qpages[value.id].timerRemaning;
595
+ localStorage.setItem('mlw_stoped_q' + quizID + '_page' + value.id, secondsRemaining);
596
+ localStorage.setItem('mlw_time_q' + quizID + '_page' + value.id, 'completed');
597
+ if (typeof qmn_quiz_data[quizID].qpages[value.id].timerInterval != 'undefined') {
598
+ clearInterval(qmn_quiz_data[quizID].qpages[value.id].timerInterval);
599
+ }
600
+ }
601
+ });
602
+ },
603
+ /**
604
+ * Converts seconds to 00:00:00 format
605
+ * @param int seconds The number of seconds
606
+ * @return string A string in H:M:S format
607
+ */
608
+ secondsToTimer: function (seconds) {
609
+ var formattedTime = '';
610
+ seconds = parseInt(seconds);
611
+ var hours = Math.floor(seconds / 3600);
612
+ if (0 === hours) {
613
+ formattedTime = '00:';
614
+ } else if (10 > hours) {
615
+ formattedTime = '0' + hours + ':';
616
+ } else {
617
+ formattedTime = hours + ':';
618
+ }
619
+ var minutes = Math.floor((seconds % 3600) / 60);
620
+ if (0 === minutes) {
621
+ formattedTime = formattedTime + '00:';
622
+ } else if (10 > minutes) {
623
+ formattedTime = formattedTime + '0' + minutes + ':';
624
+ } else {
625
+ formattedTime = formattedTime + minutes + ':';
626
+ }
627
+ var remainder = Math.floor((seconds % 60));
628
+ if (0 === remainder) {
629
+ formattedTime = formattedTime + '00';
630
+ } else if (10 > remainder) {
631
+ formattedTime = formattedTime + '0' + remainder;
632
+ } else {
633
+ formattedTime = formattedTime + remainder;
634
+ }
635
+ return formattedTime;
636
+ },
637
+ }
638
+
639
+ // On load code
640
+ $(function () {
641
+ qmnDoInit();
642
+ });
643
+ }(jQuery));
644
+
645
+ // Global Variables
646
+ var qsmTitleText = document.title;
647
+
648
+ /**
649
+ * Validates an email ID.
650
+ *
651
+ * @param email The Email Id to validate.
652
+ * @returns Boolean
653
+ */
654
+ function isEmail(email) {
655
+ var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
656
+ if (!regex.test(email)) {
657
+ return false;
658
+ } else {
659
+ return true;
660
+ }
661
+ }
662
+
663
+
664
+ /**
665
  * Limit multiple response based on question limit
666
  * @returns {undefined}
667
  */
668
+ function qsmCheckMR(event, limit) {
669
+ var checked = jQuery(event).parents('.quiz_section').find(':checkbox:checked').length;
670
+ if (checked > limit) {
671
+ event.checked = false;
672
+ if (jQuery(event).parents('.quiz_section').find('.multi-checkbox-limit-reach').length == 0) {
673
+ jQuery(event).parents('.quiz_section').append('<span class="multi-checkbox-limit-reach">' + qmn_ajax_object.multicheckbox_limit_reach + '</span>');
674
+ }
675
+ } else {
676
+ jQuery(event).parents('.quiz_section').find('.multi-checkbox-limit-reach').remove();
677
+ }
678
+ }
679
+
680
+ function qmnDoInit() {
681
+ // Legacy init.
682
+ qmnInit();
683
+
684
+ // Call main initialization.
685
+ qsminstance = QSM.init();
686
+
687
+ jQuery(".qsm-quiz-container").on("click", ".mlw_next", function () {
688
+ if (quizType == 'paginated') {
689
+ timer_ms = jQuery("input[name='timer_ms']").val();
690
+ if (timer_ms == 0) {
691
+ qsmTimerInterval = setInterval(qmnTimeTakenTimer, 1000);
692
+ jQuery("input[name='timer_ms']").each(function () {
693
+ var timems = qsmTimeInMS();
694
+ jQuery(this).val(timems);
695
+ });
696
+ }
697
+ }
698
+ });
699
+ }
700
+
701
+ function qmnTimeTakenTimer() {
702
+ var x = +jQuery('#timer').val();
703
+ if (NaN === x) {
704
+ x = 0;
705
+ }
706
+ x = x + 1;
707
+ jQuery('#timer').val(x);
708
+ }
709
+
710
+ function qsmEndTimeTakenTimer() {
711
+ clearInterval(qsmTimerInterval);
712
+ }
713
+
714
+ function qsmTimeInMS() {
715
+ var d = new Date();
716
+ var n = d.getTime();
717
+ return n;
718
+ }
719
+
720
+ function qmnClearField(field) {
721
+ if (field.defaultValue == field.value) field.value = '';
722
+ }
723
+
724
+ function qsmScrollTo($element) {
725
+ if ($element.length > 0) {
726
+ jQuery(document).trigger('qsm_scroll_to_top_before', [$element]);
727
+ jQuery('html, body').animate({ scrollTop: $element.offset().top - 150 }, 1000);
728
+ jQuery(document).trigger('qsm_scroll_to_top_after', [$element]);
729
+ }
730
+ }
731
+
732
+ function qmnDisplayError(message, field, quiz_form_id) {
733
+ jQuery('#' + quiz_form_id + ' .qmn_error_message_section').addClass('qmn_error_message');
734
+ jQuery('#' + quiz_form_id + ' .qmn_error_message').text(message);
735
+ field.closest('.quiz_section').addClass('qmn_error');
736
+ }
737
+
738
+ function qmnResetError(quiz_form_id) {
739
+ jQuery('#' + quiz_form_id + ' .qmn_error_message').text('');
740
+ jQuery('#' + quiz_form_id + ' .qmn_error_message_section').removeClass('qmn_error_message');
741
+ jQuery('#' + quiz_form_id + ' .quiz_section').removeClass('qmn_error');
742
+ }
743
+
744
+ function qmnValidation(element, quiz_form_id) {
745
+ jQuery(document).trigger('qsm_before_validation', [element, quiz_form_id]);
746
+ var result = true;
747
+ var quiz_id = +jQuery('#' + quiz_form_id).find('.qmn_quiz_id').val();
748
+ var email_error = qmn_quiz_data[quiz_id].error_messages.email;
749
+ var number_error = qmn_quiz_data[quiz_id].error_messages.number;
750
+ var empty_error = qmn_quiz_data[quiz_id].error_messages.empty;
751
+ var incorrect_error = qmn_quiz_data[quiz_id].error_messages.incorrect;
752
+ qmnResetError(quiz_form_id);
753
+ jQuery(element).each(function () {
754
+ if (jQuery(this).attr('class')) {
755
+ if (jQuery(this).attr('class').indexOf('mlwEmail') !== -1 && this.value !== "") {
756
+ // Remove any trailing and preceeding space.
757
+ var x = jQuery.trim(this.value);
758
+ if (!isEmail(x)) {
759
+ qmnDisplayError(email_error, jQuery(this), quiz_form_id);
760
+ result = false;
761
+ }
762
+ }
763
+ var by_pass = true;
764
+ if (qmn_quiz_data[quizID].timer_limit_val > 0 && qmn_quiz_data[quiz_id].hasOwnProperty('skip_validation_time_expire') && qmn_quiz_data[quiz_id].skip_validation_time_expire == 0) {
765
+ by_pass = false;
766
+ }
767
+
768
+ if (localStorage.getItem('mlw_time_quiz' + quiz_id) === null || localStorage.getItem('mlw_time_quiz' + quiz_id) > 0.08 || by_pass === false) {
769
+
770
+ if (jQuery(this).attr('class').indexOf('mlwRequiredNumber') > -1 && this.value === "" && +this.value != NaN) {
771
+ qmnDisplayError(number_error, jQuery(this), quiz_form_id);
772
+ result = false;
773
+ }
774
+ if (jQuery(this).attr('class').indexOf('mlwRequiredDate') > -1 && this.value === "") {
775
+ qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
776
+ result = false;
777
+ }
778
+ if (jQuery(this).attr('class').indexOf('mlwRequiredText') > -1 && jQuery.trim(this.value) === "") {
779
+ qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
780
+ result = false;
781
+ }
782
+ if (jQuery(this).attr('class').indexOf('mlwRequiredCaptcha') > -1 && this.value != mlw_code) {
783
+ qmnDisplayError(incorrect_error, jQuery(this), quiz_form_id);
784
+ result = false;
785
+ }
786
+ if (jQuery(this).attr('class').indexOf('mlwRequiredAccept') > -1 && !jQuery(this).prop('checked')) {
787
+ qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
788
+ result = false;
789
+ }
790
+ if (jQuery(this).attr('class').indexOf('mlwRequiredRadio') > -1) {
791
+ check_val = jQuery(this).find('input:checked').val();
792
+ if (check_val == "No Answer Provided" || check_val == "" || check_val == undefined) {
793
+ qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
794
+ result = false;
795
+ }
796
+ }
797
+ if (jQuery(this).attr('class').indexOf('mlwRequiredFileUpload') > -1) {
798
+ var selected_file = jQuery(this).get(0).files.length;
799
+ if (selected_file === 0) {
800
+ qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
801
+ result = false;
802
+ }
803
+ }
804
+ if (jQuery(this).attr('class').indexOf('qsmRequiredSelect') > -1) {
805
+ check_val = jQuery(this).val();
806
+ if (check_val == "No Answer Provided" || check_val == "") {
807
+ qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
808
+ result = false;
809
+ }
810
+ }
811
+ if (jQuery(this).attr('class').indexOf('mlwRequiredCheck') > -1) {
812
+ if (!jQuery(this).find('input:checked').length) {
813
+ qmnDisplayError(empty_error, jQuery(this), quiz_form_id);
814
+ result = false;
815
+ }
816
+ }
817
+ //Google recaptcha validation
818
+ if (jQuery(this).attr('class').indexOf('g-recaptcha-response') > -1) {
819
+ if (grecaptcha.getResponse() == "") {
820
+ alert('ReCaptcha is missing');
821
+ result = false;
822
+ }
823
+ }
824
+ }
825
+ }
826
+ });
827
+ jQuery(document).trigger('qsm_after_validation', [element, quiz_form_id]);
828
+ return result;
829
+ }
830
+
831
+ function getFormData($form) {
832
+ var unindexed_array = $form.serializeArray();
833
+ var indexed_array = {};
834
+
835
+ jQuery.map(unindexed_array, function (n, i) {
836
+ indexed_array[n['name']] = n['value'];
837
+ });
838
+
839
+ return indexed_array;
840
+ }
841
+
842
+ function qmnFormSubmit(quiz_form_id) {
843
+ var quiz_id = +jQuery('#' + quiz_form_id).find('.qmn_quiz_id').val();
844
+ var $container = jQuery('#' + quiz_form_id).closest('.qmn_quiz_container');
845
+ var result = qmnValidation('#' + quiz_form_id + ' *', quiz_form_id);
846
+
847
+ if (!result) { return result; }
848
+
849
+ /**
 
850
  * Update Timer in MS
851
  */
852
+ var timer_ms = jQuery('#' + quiz_form_id).find("input[name='timer_ms']").val();
853
+ var new_timer_ms = qsmTimeInMS();
854
+ jQuery('#' + quiz_form_id).find("input[name='timer_ms']").val(Math.abs(new_timer_ms - timer_ms));
855
+
856
+ jQuery('.mlw_qmn_quiz input:radio').attr('disabled', false);
857
+ jQuery('.mlw_qmn_quiz input:checkbox').attr('disabled', false);
858
+ jQuery('.mlw_qmn_quiz select').attr('disabled', false);
859
+ jQuery('.mlw_qmn_question_comment').attr('disabled', false);
860
+ jQuery('.mlw_answer_open_text').attr('disabled', false);
861
+
862
+ //Convert serialize data into index array
863
+ var unindexed_array = jQuery('#' + quiz_form_id).serializeArray();
864
+ var fd = new FormData();
865
+ jQuery.each(unindexed_array, function (key, input) {
866
+ fd.append(input.name, input.value);
867
+ });
868
+ fd.append("action", 'qmn_process_quiz');
869
+ fd.append("currentuserTime", Math.round(new Date().getTime()/1000));
870
+ fd.append("currentuserTimeZone",Intl.DateTimeFormat().resolvedOptions().timeZone);
871
+
872
+
873
+ qsmEndTimeTakenTimer();
874
+ if (qmn_quiz_data[quizID].hasOwnProperty('advanced_timer')) {
875
+ QSMPageTimer.endPageTimer(quiz_id);
876
+ }
877
+ if (qmn_quiz_data[quiz_id].hasOwnProperty('timer_limit')) {
878
+ QSM.endTimer(quiz_id);
879
+ }
880
+ jQuery(document).trigger('qsm_before_quiz_submit', [quiz_form_id]);
881
+ jQuery('#' + quiz_form_id + ' input[type=submit]').attr('disabled', 'disabled');
882
+ qsmDisplayLoading($container, quiz_id);
883
+ // console.log( 'submitted data:' + unindexed_array );
884
+ jQuery.ajax({
885
+ url: qmn_ajax_object.ajaxurl,
886
+ data: fd,
887
+ contentType: false,
888
+ processData: false,
889
+ type: 'POST',
890
+ success: function (response) {
891
+ response=JSON.parse(response);
892
+ if (window.qsm_results_data === undefined) {
893
+ window.qsm_results_data = new Object();
894
+ }
895
+ window.qsm_results_data[quizID]={
896
+ 'save_response' : response.result_status['save_response'],
897
+ 'id' : response.result_status['id']
898
+ };
899
+
900
+ if(response.quizExpired){
901
+ MicroModal.show('modal-4');
902
+ return false;
903
+ }else{
904
+ qmnDisplayResults(response, quiz_form_id, $container);
905
+ jQuery(document).trigger('qsm_after_quiz_submit_load_chart');
906
+ jQuery(document).trigger('qsm_after_quiz_submit', [quiz_form_id]);
907
+ }
908
+ }
909
+ });
910
+
911
+ return false;
912
+ }
913
+
914
+ function qsmDisplayLoading($container, quiz_id) {
915
+ var loader_html = '<div class="qsm_quiz_processing_box">';
916
+ loader_html += '<div class="qsm-spinner-loader qsm_quiz_processing_loader"></div>';
917
+ if (qmn_quiz_data[quiz_id].hasOwnProperty('quiz_processing_message') && qmn_quiz_data[quiz_id].quiz_processing_message != '') {
918
+ loader_html += '<div class="qsm_quiz_processing_message">'+qmn_quiz_data[quiz_id].quiz_processing_message+'</div>';
919
+ }
920
+ loader_html += '</div>';
921
+ $container.empty();
922
+ $container.append(loader_html);
923
+ qsmScrollTo($container);
924
+ }
925
+
926
+ function qmnDisplayResults(results, quiz_form_id, $container) {
927
+ $container.empty();
928
+ jQuery(document).trigger('qsm_before_display_result', [results, quiz_form_id, $container]);
929
+ if (results.redirect) {
930
+ window.location.replace(results.redirect);
931
+ } else {
932
+ $container.append('<div class="qmn_results_page"></div>');
933
+ $container.find('.qmn_results_page').html(results.display);
934
+ qsmScrollTo($container);
935
+ // run MathJax on the new content
936
+ MathJax.typesetPromise();
937
+ // Fires after result is populates via ajax
938
+ jQuery(document).trigger('qsm_after_display_result', [results, quiz_form_id, $container]);
939
+ }
940
+ }
941
+
942
+ function qmnInit() {
943
+ if (typeof qmn_quiz_data != 'undefined' && qmn_quiz_data) {
944
+ let key = Object.keys(qmn_quiz_data)[0];
945
+ if (qmn_quiz_data[key].ajax_show_correct === '1') {
946
+ jQuery('#quizForm' + qmn_quiz_data[key].quiz_id + ' .qmn_quiz_radio').change(function () {
947
+ var chosen_answer = jQuery(this).val();
948
+ var question_id = jQuery(this).attr('name').replace(/question/i, '');
949
+ var chosen_id = jQuery(this).attr('id');
950
+ jQuery.each(qmn_quiz_data[key].question_list, function (i, value) {
951
+ if (question_id == value.question_id) {
952
+ jQuery.each(value.answers, function (j, answer) {
953
+ if (answer[0] === chosen_answer) {
954
+ if (answer[2] !== 1) {
955
+ jQuery('#' + chosen_id).parent().addClass("qmn_incorrect_answer");
956
+ }
957
+ }
958
+ if (answer[2] === 1) {
959
+ jQuery(':radio[name=question' + question_id + '][value="' + answer[0] + '"]').parent().addClass("qmn_correct_answer");
960
+ }
961
+ });
962
+ }
963
+ });
964
+ });
965
+ }
966
+
967
+ if (qmn_quiz_data[key].disable_answer === '1') {
968
+
969
+ jQuery('#quizForm' + qmn_quiz_data[key].quiz_id + ' .qmn_quiz_radio').change(function () {
970
+ var radio_group = jQuery(this).attr('name');
971
+ jQuery('input[type=radio][name=' + radio_group + ']').prop('disabled', true);
972
+ let radio_value =jQuery(this).val();
973
+ let disableAnswer = {};
974
+ if ( localStorage.getItem( "disable_answer" ) ){
975
+ disableAnswer = JSON.parse(localStorage.getItem("disable_answer"));
976
+ }
977
+ if (!disableAnswer[key]){
978
+ disableAnswer[key]=[];
979
+ }
980
+ let disabledQuestions = disableAnswer[key].map(element => element[0]);
981
+ if (! disabledQuestions.includes(radio_group) ){
982
+ disableAnswer[key].push([radio_group, radio_value]);
983
+ }
984
+ localStorage.setItem("disable_answer",JSON.stringify(disableAnswer));
985
+ });
986
+
987
+ if(localStorage.getItem("disable_answer")){
988
+ let disabledAnswer = JSON.parse(localStorage.getItem("disable_answer"));
989
+ if(disabledAnswer[key]){
990
+ disabledAnswer[key].forEach(element => {
991
+ let element1=element[1].replaceAll(' ','-');
992
+ jQuery('#'+element[0]+'-'+element1+' input').prop('checked', true).trigger('change');
993
+ });
994
+ }
995
+ }
996
+ jQuery(document).on('qsm_after_quiz_submit',function(event, quiz_form_id ){
997
+ event.preventDefault();
998
+ if(localStorage.getItem("disable_answer")){
999
+ let disabledAnswer2 = JSON.parse(localStorage.getItem("disable_answer"));
1000
+ if(disabledAnswer2[key]){
1001
+ delete disabledAnswer2[key];
1002
+ localStorage.setItem("disable_answer",JSON.stringify(disabledAnswer2)); }
1003
+ }
1004
+ });
1005
+ }
1006
+
1007
+ if (qmn_quiz_data[key].hasOwnProperty('pagination')) {
1008
+ qmnInitPagination(qmn_quiz_data[key].quiz_id);
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ //Function to validate the answers provided in quiz
1014
+ function qmnValidatePage(quiz_form_id) {
1015
+ var result = qmnValidation('#' + quiz_form_id + ' .quiz_section:visible *', quiz_form_id);
1016
+ return result;
1017
+ }
1018
+
1019
+ //Function to advance quiz to next page
1020
+ function qmnNextSlide(pagination, go_to_top, quiz_form_id) {
1021
+ jQuery(document).trigger('qsm_next_button_click_before', [quiz_form_id]);
1022
+ var quiz_id = +jQuery(quiz_form_id).find('.qmn_quiz_id').val();
1023
+ var $container = jQuery(quiz_form_id).closest('.qmn_quiz_container');
1024
+ var slide_number = +$container.find('.slide_number_hidden').val();
1025
+ var page_number = +$container.find('.current_page_hidden').val();
1026
+ var section_totals = +$container.find('.total_sections_hidden').val();
1027
+ if (pagination == 1) {
1028
+ section_totals = section_totals - 1;
1029
+ }
1030
+ var total_pages = $container.find('.total_pages_hidden').val();
1031
+
1032
+ jQuery(quiz_form_id + " .qsm-auto-page-row").hide();
1033
+ if (page_number >= total_pages) {
1034
+ alert('Next page not found.');
1035
+ $container.find(".mlw_next").hide();
1036
+ jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_end").show();
1037
+ return true;
1038
+ }
1039
+ if (slide_number == 0 && page_number == 0) {
1040
+ jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_begin").show();
1041
+ $container.find(".mlw_previous").hide();
1042
+ $container.find('.current_page_hidden').val('1');
1043
+ } else if (total_pages == parseInt(page_number) + 1) { //Last page
1044
+ $container.find(".mlw_next").hide();
1045
+ jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_end").show();
1046
+ $container.find('.slide_number_hidden').val(parseInt(slide_number) + 1);
1047
+ $container.find('.current_page_hidden').val(parseInt(page_number) + 1);
1048
+ $container.find(".mlw_previous").show();
1049
+ $container.find('.g-recaptcha').show();
1050
+ } else if (slide_number >= 0 && page_number >= 1) {
1051
+ if (total_pages == parseInt(page_number) + 2) { // if last page empty
1052
+ if (jQuery(quiz_form_id + " .qsm-auto-page-row.empty_quiz_end").length) {
1053
+ submit_button = jQuery(quiz_form_id + " .qsm-auto-page-row.empty_quiz_end").html();
1054
+ jQuery(quiz_form_id + " .qsm-auto-page-row.empty_quiz_end").show();
1055
+ $container.find(".mlw_next").hide();
1056
+ $container.find('.g-recaptcha').show();
1057
+ }
1058
+ }
1059
+ $container.find('.qsm-auto-page-row.qsm-apc-' + page_number).show();
1060
+ $container.find('.slide_number_hidden').val(parseInt(slide_number) + 1);
1061
+ $container.find('.current_page_hidden').val(parseInt(page_number) + 1);
1062
+ $container.find(".mlw_previous").show();
1063
+ }
1064
+ if (jQuery(quiz_form_id + " .quiz_section.quiz_end").is(':visible')) {
1065
+ var button_width = jQuery(quiz_form_id + ' .qsm-submit-btn').width();
1066
+ var progress_width = jQuery(quiz_form_id).parent().find('.qmn_pagination').width();
1067
+ jQuery(quiz_form_id).parent().find('.qmn_pagination').css('width', progress_width - button_width - 40);
1068
+ } else {
1069
+ jQuery(quiz_form_id).parent().find('.qmn_pagination').css('width', '100%');
1070
+ }
1071
+ if (go_to_top == 1 && qmn_quiz_data[quiz_id].disable_scroll_next_previous_click != 1) {
1072
+ qsmScrollTo($container);
1073
+ }
1074
+ if (qmn_quiz_data[quiz_id].disable_first_page == 1) {
1075
+ if (slide_number == 0 && page_number == 0) {
1076
+ $container.find(".qsm-auto-page-row.quiz_begin").hide();
1077
+ $container.find('.qsm-auto-page-row.qsm-apc-' + (parseInt(page_number) + 1)).show();
1078
+ $container.find('.slide_number_hidden').val(parseInt(slide_number) + 1);
1079
+ $container.find('.current_page_hidden').val(parseInt(page_number) + 2);
1080
+ $container.find(".mlw_previous").hide();
1081
+ }
1082
+ }
1083
+ //Show the page counts
1084
+ if (page_number > 0 && jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').length > 0) {
1085
+ var actual_pages = total_pages - 2;
1086
+ if (page_number <= actual_pages) {
1087
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').text('').text(page_number + qmn_ajax_object.out_of_text + actual_pages);
1088
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').show();
1089
+ } else {
1090
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1091
+ }
1092
+ } else {
1093
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1094
+ }
1095
+ qmnInitProgressbarOnClick(quiz_id, page_number, total_pages);
1096
+ jQuery(document).trigger('qsm_auto_next_button_click_after', [quiz_form_id]);
1097
+ }
1098
+
1099
+ function qmnPrevSlide(pagination, go_to_top, quiz_form_id) {
1100
+ jQuery(document).trigger('qsm_previous_button_click_before', [quiz_form_id]);
1101
+ var quiz_id = +jQuery(quiz_form_id).find('.qmn_quiz_id').val();
1102
+ var $container = jQuery(quiz_form_id).closest('.qmn_quiz_container');
1103
+ var slide_number = +$container.find('.slide_number_hidden').val();
1104
+ var previous = +$container.find('.previous_amount_hidden').val();
1105
+ var section_totals = +$container.find('.total_sections_hidden').val();
1106
+ var page_number = +$container.find('.current_page_hidden').val();
1107
+ var total_pages = $container.find('.total_pages_hidden').val();
1108
+ jQuery(quiz_form_id + " .qsm-auto-page-row").hide();
1109
+ jQuery(quiz_form_id + " .g-recaptcha").hide();
1110
+ var slide_original_val = parseInt(slide_number) - 1;
1111
+ if (slide_original_val == 0) {
1112
+ $container.find(".mlw_next").show();
1113
+ jQuery(quiz_form_id + " .qsm-auto-page-row.quiz_begin").show();
1114
+ $container.find('.slide_number_hidden').val(slide_original_val);
1115
+ $container.find('.current_page_hidden').val(parseInt(page_number) - 1);
1116
+ $container.find(".mlw_previous").hide();
1117
+ } else {
1118
+ $container.find('.qsm-auto-page-row.qsm-apc-' + slide_original_val).show();
1119
+ $container.find('.slide_number_hidden').val(slide_original_val);
1120
+ $container.find('.current_page_hidden').val(parseInt(page_number) - 1);
1121
+ $container.find(".mlw_next").show();
1122
+ }
1123
+ if (go_to_top == 1 && qmn_quiz_data[quiz_id].disable_scroll_next_previous_click != 1) {
1124
+ qsmScrollTo($container);
1125
+ }
1126
+ if (qmn_quiz_data[quiz_id].disable_first_page == 1) {
1127
+ if (page_number == 3) {
1128
+ $container.find(".qsm-auto-page-row.quiz_begin").hide();
1129
+ $container.find(".mlw_previous").hide();
1130
+ }
1131
+ }
1132
+ if (page_number > 0 && jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').length > 0) {
1133
+ var actual_pages = total_pages - 2;
1134
+ if (slide_original_val <= actual_pages) {
1135
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').text('').text(slide_original_val + qmn_ajax_object.out_of_text + actual_pages);
1136
+ if (slide_original_val == 0) {
1137
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1138
+ } else {
1139
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').show();
1140
+ }
1141
+ } else {
1142
+ jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.pages_count').hide();
1143
+ }
1144
+ }
1145
+ jQuery(quiz_form_id).parent().find('.qmn_pagination').css('width', '100%');
1146
+ qmnInitProgressbarOnClick(quiz_id, slide_original_val, total_pages);
1147
+ jQuery(document).trigger('qsm_auto_previous_button_click_after', [quiz_form_id]);
1148
+ }
1149
+
1150
+ /**
1151
+ * @since 6.4.11
1152
+ * @param {int} quiz_id
1153
+ * @param {int} page_number
1154
+ * @param {int} total_page_number
1155
+ * @returns Change progress bar on next and previous button click
1156
+ */
1157
+ function qmnInitProgressbarOnClick(quiz_id, page_number, total_page_number) {
1158
+ if ('1' == qmn_quiz_data[quiz_id].progress_bar) {
1159
+ var qmn_total_questions = qmn_quiz_data[quiz_id].pagination.total_questions;
1160
+ var pagination = qmn_quiz_data[quiz_id].pagination.amount;
1161
+ total_page_number = Math.ceil(qmn_total_questions / pagination);
1162
+ if (!jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').find('.empty_quiz_end').length) {
1163
+ total_page_number = total_page_number + 1; //Increase for quiz end section
1164
+ }
1165
+ var animate_value = page_number / total_page_number;
1166
+ if (animate_value <= 1) {
1167
+ qmn_quiz_data[quiz_id].bar.animate(animate_value);
1168
+ var old_text = jQuery('#qsm_progress_bar_' + quiz_id).find('.progressbar-text').text().replace(' %', '');
1169
+ var new_text = Math.round(animate_value * 100);
1170
+ jQuery({
1171
+ Counter: old_text
1172
+ }).animate({
1173
+ Counter: new_text
1174
+ }, {
1175
+ duration: 1000,
1176
+ easing: 'swing',
1177
+ step: function () {
1178
+ jQuery('#qsm_progress_bar_' + quiz_id).find('.progressbar-text').text(Math.round(this.Counter) + ' %');
1179
+ }
1180
+ });
1181
+ }
1182
+ }
1183
+ }
1184
+
1185
+ function qmnUpdatePageNumber(amount, quiz_form_id) {
1186
+ var current_page = +jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.current_page_hidden').val();
1187
+ var total_pages = jQuery(quiz_form_id).closest('.qmn_quiz_container').find('.total_pages_hidden').val();
1188
+ current_page += amount;
1189
+ //jQuery( quiz_form_id ).siblings( '.qmn_pagination' ).find( " .qmn_page_counter_message" ).text( current_page + "/" + total_pages );
1190
+ }
1191
+
1192
+ function qmnInitPagination(quiz_id) {
1193
+ var qmn_section_total = +qmn_quiz_data[quiz_id].pagination.total_questions;
1194
+ var qmn_total_pages = Math.ceil(qmn_section_total / +qmn_quiz_data[quiz_id].pagination.amount);
1195
+
1196
+ qmn_total_pages = qmn_total_pages + 1; //quiz begin
1197
+ qmn_total_pages = qmn_total_pages + 1; //quiz end
1198
+
1199
+
1200
+ jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').append('<div class="qmn_pagination border margin-bottom"></div>');
1201
+ jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').find('.qmn_pagination').append('<input type="hidden" value="0" name="slide_number" class="slide_number_hidden" />')
1202
+ .append('<input type="hidden" value="0" name="current_page" class="current_page_hidden" />')
1203
+ .append('<input type="hidden" value="' + qmn_total_pages + '" name="total_pages" class="total_pages_hidden" />')
1204
+ .append('<input type="hidden" value="' + qmn_section_total + '" name="total_sections" class="total_sections_hidden" />')
1205
+ .append('<input type="hidden" value="0" name="previous_amount" class="previous_amount_hidden" />')
1206
+ .append('<a class="qmn_btn mlw_qmn_quiz_link mlw_previous" href="#">' + qmn_quiz_data[quiz_id].pagination.previous_text + '</a>')
1207
+ .append('<span class="qmn_page_message"></span>')
1208
+ .append('<div class="qmn_page_counter_message"></div>')
1209
+ .append('<div class="qsm-progress-bar" id="qsm_progress_bar_' + quiz_id + '" style="display:none;"><div class="progressbar-text"></div></div>')
1210
+ .append('<a class="qmn_btn mlw_qmn_quiz_link mlw_next" href="#">' + qmn_quiz_data[quiz_id].pagination.next_text + '</a>');
1211
+
1212
+ if ('1' == qmn_quiz_data[quiz_id].progress_bar) {
1213
+ jQuery(document).trigger('qsm_init_progressbar_before', [quiz_id, qmn_quiz_data]);
1214
+ jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container').find('.qsm-progress-bar').show();
1215
+ qmn_quiz_data[quiz_id].bar = new ProgressBar.Line('#qsm_progress_bar_' + quiz_id, {
1216
+ strokeWidth: 2,
1217
+ easing: 'easeInOut',
1218
+ duration: 500,
1219
+ color: '#3498db',
1220
+ trailColor: '#eee',
1221
+ trailWidth: 1,
1222
+ svgStyle: { width: '100%', height: '100%' },
1223
+ text: {
1224
+ style: {
1225
+ // color: '#999',
1226
+ position: 'absolute',
1227
+ padding: 0,
1228
+ margin: 0,
1229
+ top: 0,
1230
+ right: '10px',
1231
+ 'font-size': '13px',
1232
+ 'font-weight': 'bold',
1233
+ transform: null
1234
+ },
1235
+ autoStyleContainer: false
1236
+ },
1237
+ from: { color: '#3498db' },
1238
+ to: { color: '#ED6A5A' },
1239
+ step: function (state, bar) {
1240
+ }
1241
+ });
1242
+ jQuery(document).trigger('qsm_init_progressbar_after', [quiz_id, qmn_quiz_data]);
1243
+ }
1244
+
1245
+ jQuery(".mlw_next").click(function (event) {
1246
+ event.preventDefault();
1247
+ var quiz_id = +jQuery(this).closest('.qmn_quiz_container').find('.qmn_quiz_id').val();
1248
+ jQuery(document).trigger('qsm_auto_next_button_click_before', [quiz_id]);
1249
+ if (qmnValidatePage('quizForm' + quiz_id)) {
1250
+ qmnNextSlide(qmn_quiz_data[quiz_id].pagination.amount, 1, '#quizForm' + quiz_id);
1251
+ }
1252
+ });
1253
+
1254
+ jQuery(".mlw_previous").click(function (event) {
1255
+ event.preventDefault();
1256
+ var quiz_id = +jQuery(this).closest('.qmn_quiz_container').find('.qmn_quiz_id').val();
1257
+ qmnPrevSlide(qmn_quiz_data[quiz_id].pagination.amount, 1, '#quizForm' + quiz_id);
1258
+ });
1259
+
1260
+ if (qmn_quiz_data[quiz_id].first_page) {
1261
+ qmnNextSlide(1, 0, '#quizForm' + quiz_id);
1262
+ } else {
1263
+ qmnNextSlide(qmn_quiz_data[quiz_id].pagination.amount, 0, '#quizForm' + quiz_id);
1264
+ }
1265
+
1266
+ }
1267
+
1268
+ function qmnSocialShare(network, mlw_qmn_social_text, mlw_qmn_title, facebook_id, share_url) {
1269
+ var sTop = window.screen.height / 2 - (218);
1270
+ var sLeft = window.screen.width / 2 - (313);
1271
+ var sqShareOptions = "height=400,width=580,toolbar=0,status=0,location=0,menubar=0,directories=0,scrollbars=0,top=" + sTop + ",left=" + sLeft;
1272
+ var pageUrl = window.location.href;
1273
+ var pageUrlEncoded = encodeURIComponent(share_url);
1274
+ var url = '';
1275
+ if (network == 'facebook') {
1276
+ url = "https://www.facebook.com/dialog/feed?" + "display=popup&" + "app_id=" + facebook_id +
1277
+ "&" + "link=" + pageUrlEncoded + "&" + "name=" + encodeURIComponent(mlw_qmn_social_text) +
1278
+ "&" + "description=";
1279
+ }
1280
+ if (network == 'twitter') {
1281
+ url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(mlw_qmn_social_text);
1282
+ }
1283
+ window.open(url, "Share", sqShareOptions);
1284
+ return false;
1285
+ }
1286
+
1287
+ jQuery(function () {
1288
+ jQuery('.qmn_quiz_container').tooltip();
1289
+
1290
+ jQuery('.qmn_quiz_container input').on('keypress', function (e) {
1291
+ if (e.which === 13) {
1292
+ e.preventDefault();
1293
+ }
1294
+ });
1295
+
1296
+ jQuery(document).on('click', ".qsm-submit-btn", function (event) {
1297
+ event.preventDefault();
1298
+ var form = jQuery(this).closest('form')[0];
1299
+ var form_id = form.id;
1300
+ var recaptcha = jQuery('#' + form_id).find("#qsm_grecaptcha_v3");
1301
+ if ( ! recaptcha.length ) {
1302
+ qmnFormSubmit(form_id);
1303
+ return false;
1304
+ }
1305
+
1306
+ // Proceed reCaptcha v3
1307
+ var site_key = jQuery('#' + form_id).find("#qsm_grecaptcha_v3_sitekey").val();
1308
+ var submit_action = jQuery('#' + form_id).find("#qsm_grecaptcha_v3_nonce").val();
1309
+ grecaptcha.ready(function() {
1310
+ grecaptcha.execute(site_key, {action: submit_action}).then(function(token) {
1311
+ jQuery('#' + form_id).find("#qsm_grecaptcha_v3_response").val(token);
1312
+ qmnFormSubmit(form_id);
1313
+ });
1314
+ });
1315
+ });
1316
+
1317
+ jQuery(document).on('click', '.btn-reload-quiz', function (e) {
1318
+ e.preventDefault();
1319
+ var quiz_id = jQuery(this).data('quiz_id');
1320
+ var parent_div = jQuery(this).parents('.qsm-quiz-container');
1321
+ qsmDisplayLoading(parent_div, quiz_id);
1322
+ jQuery.ajax({
1323
+ type: 'POST',
1324
+ url: qmn_ajax_object.ajaxurl,
1325
+ data: {
1326
+ action: "qsm_get_quiz_to_reload",
1327
+ quiz_id: quiz_id,
1328
+ },
1329
+ success: function (response) {
1330
+ parent_div.replaceWith(response);
1331
+ //Reload the timer and pagination
1332
+ qmnDoInit();
1333
+
1334
+ MathJax.typesetPromise();
1335
+
1336
+ // trigger fired on successfull retake quiz
1337
+ jQuery(document).trigger('qsm_retake_quiz', [quiz_id]);
1338
+ },
1339
+ error: function (errorThrown) {
1340
+ console.log('error');
1341
+ }
1342
+ });
1343
+ });
1344
+
1345
+ jQuery(document).on('change', '.qmn_radio_answers input', function (e) {
1346
+ var quizID = jQuery(this).parents('.qsm-quiz-container').find('.qmn_quiz_id').val();
1347
+ if (qmn_quiz_data[quizID].enable_quick_result_mc == 1) {
1348
+ var question_id = jQuery(this).attr('name').split('question')[1],
1349
+ value = jQuery(this).val(),
1350
+ $this = jQuery(this).parents('.quiz_section');
1351
+ jQuery.ajax({
1352
+ type: 'POST',
1353
+ url: qmn_ajax_object.ajaxurl,
1354
+ data: {
1355
+ action: "qsm_get_question_quick_result",
1356
+ question_id: question_id,
1357
+ answer: value,
1358
+ show_correct_info: qmn_quiz_data[quizID].enable_quick_correct_answer_info
1359
+ },
1360
+ success: function (response) {
1361
+ var data = jQuery.parseJSON(response);
1362
+ $this.find('.quick-question-res-p').remove();
1363
+ $this.find('.qsm-inline-correct-info').remove();
1364
+ if (data.success == 'correct') {
1365
+ $this.append('<div style="color: green" class="quick-question-res-p">' + qmn_quiz_data[quizID].quick_result_correct_answer_text + '</div>')
1366
+ $this.append('<div class="qsm-inline-correct-info">' + data.message + '</div>');
1367
+ } else if (data.success == 'incorrect') {
1368
+ $this.append('<div style="color: red" class="quick-question-res-p">' + qmn_quiz_data[quizID].quick_result_wrong_answer_text + '</div>')
1369
+ $this.append('<div class="qsm-inline-correct-info">' + data.message + '</div>');
1370
+ }
1371
+ MathJax.typesetPromise();
1372
+ },
1373
+ error: function (errorThrown) {
1374
+ alert(errorThrown);
1375
+ }
1376
+ });
1377
+ }
1378
+ });
1379
+
1380
+ // Autocomplete off
1381
+ jQuery('.qsm-quiz-container').find('.qmn_quiz_id').each(function (){
1382
+ var quizID = jQuery(this).val();
1383
+ var $quizForm = QSM.getQuizForm(quizID);
1384
+ if (qmn_quiz_data[quizID].form_disable_autofill == 1) {
1385
+ jQuery('#quizForm' + quizID).attr('autocomplete', 'off');
1386
+ }
1387
+ });
1388
+
1389
+ // End Quiz If Wrong
1390
+ jQuery(document).on('change ', '.qmn_radio_answers input , .qmn_check_answers input , .qsm_select', function (e) {
1391
+ var quizID = jQuery(this).parents('.qsm-quiz-container').find('.qmn_quiz_id').val();
1392
+ var $quizForm = QSM.getQuizForm(quizID);
1393
+ if (qmn_quiz_data[quizID].end_quiz_if_wrong == 1) {
1394
+ var question_id = jQuery(this).attr('name').split('question')[1],
1395
+ value = jQuery(this).val(),
1396
+ $this = jQuery(this).parents('.quiz_section');
1397
+ jQuery.ajax({
1398
+ type: 'POST',
1399
+ url: qmn_ajax_object.ajaxurl,
1400
+ data: {
1401
+ action: "qsm_get_question_quick_result",
1402
+ question_id: question_id,
1403
+ answer: value,
1404
+ show_correct_info: qmn_quiz_data[quizID].enable_quick_correct_answer_info
1405
+ },
1406
+ success: function (response) {
1407
+ var data = jQuery.parseJSON(response);
1408
+ $this.find('.quick-question-res-p').remove();
1409
+ $this.find('.qsm-inline-correct-info').remove();
1410
+ if (data.success == 'correct') {
1411
+ } else if (data.success == 'incorrect') {
1412
+ $this.append('<div style="color: red" class="quick-question-res-p">' + qmn_quiz_data[quizID].quick_result_wrong_answer_text + '</div>')
1413
+ $this.append('<div class="qsm-inline-correct-info">' + data.message + '</div>');
1414
+ setTimeout(function () {
1415
+ $quizForm.closest('.qmn_quiz_container').find('.qsm-submit-btn').trigger('click');
1416
+ }, 1000);
1417
+ }
1418
+ MathJax.typesetPromise();
1419
+ },
1420
+ error: function (errorThrown) {
1421
+ alert(errorThrown);
1422
+ }
1423
+ });
1424
+ }
1425
+ });
1426
+
1427
+ //Ajax upload file code
1428
+ jQuery('.quiz_section .mlw_answer_file_upload').on('change', function () {
1429
+ var $this = jQuery(this);
1430
+ var file_data = jQuery(this).prop('files')[0];
1431
+ var form_data = new FormData();
1432
+ form_data.append('file', file_data);
1433
+ form_data.append('action', 'qsm_upload_image_fd_question');
1434
+ var question_id = $this.parent('.quiz_section').find('.mlw_file_upload_hidden_value').attr("name").replace('question', '');
1435
+ form_data.append('question_id', question_id);
1436
+ $this.next('.loading-uploaded-file').show();
1437
+ jQuery.ajax({
1438
+ url: qmn_ajax_object.ajaxurl,
1439
+ type: 'POST',
1440
+ data: form_data,
1441
+ cache: false,
1442
+ contentType: false,
1443
+ processData: false,
1444
+ success: function (response) {
1445
+ var obj = jQuery.parseJSON(response);
1446
+ $this.next('.loading-uploaded-file').hide();
1447
+ if (obj.type == 'success') {
1448
+ $this.next().next('.remove-uploaded-file').show();
1449
+ $this.next().next().next('.mlw_file_upload_hidden_value').val(obj.file_url);
1450
+ $this.parent('.quiz_section').find('.mlw_file_upload_hidden_path').val(obj.file_path);
1451
+ $this.parent('.quiz_section').find('.mlw_file_upload_media_id').val(obj.media_id);
1452
+ $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').hide();
1453
+ } else {
1454
+ $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').text('').text(obj.message);
1455
+ $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').show();
1456
+ $this.parent('.quiz_section').find('.mlw_answer_file_upload').val('');
1457
+ }
1458
+ // triggers after file uploads
1459
+ jQuery(document).trigger('qsm_after_file_upload', [$this.parent(), obj]);
1460
+ }
1461
+ });
1462
+ return false;
1463
+ });
1464
+
1465
+ //Ajax remove file code
1466
+ jQuery('.quiz_section .remove-uploaded-file').on('click', function () {
1467
+ var $this = jQuery(this);
1468
+ var media_id = jQuery(this).parent('.quiz_section').find('.mlw_file_upload_media_id').val();
1469
+ var form_data = new FormData();
1470
+ form_data.append('action', 'qsm_remove_file_fd_question');
1471
+ form_data.append('media_id', media_id);
1472
+ jQuery.ajax({
1473
+ url: qmn_ajax_object.ajaxurl,
1474
+ type: 'POST',
1475
+ data: form_data,
1476
+ cache: false,
1477
+ contentType: false,
1478
+ processData: false,
1479
+ success: function (response) {
1480
+ var obj = jQuery.parseJSON(response);
1481
+ if (obj.type == 'success') {
1482
+ $this.hide();
1483
+ $this.parent('.quiz_section').find('.mlw_file_upload_hidden_value').val('');
1484
+ $this.parent('.quiz_section').find('.mlw_file_upload_hidden_path').val('');
1485
+ $this.parent('.quiz_section').find('.mlw_file_upload_media_id').val('');
1486
+ $this.parent('.quiz_section').find('.mlw_answer_file_upload').val('');
1487
+ $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').hide();
1488
+ } else {
1489
+ $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').text('').text(obj.message);
1490
+ $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').show();
1491
+ }
1492
+ }
1493
+ });
1494
+ return false;
1495
+ });
1496
+
1497
+ //Deselect all answer on select
1498
+ jQuery('.qsm-deselect-answer').click(function (e) {
1499
+ e.preventDefault();
1500
+ jQuery(this).parents('.quiz_section').find('input[type="radio"]').prop('checked', false);
1501
+ jQuery(this).parents('.quiz_section').find('input[type="radio"][value="No Answer Provided"]').prop('checked', true);
1502
+ jQuery(this).parents('.quiz_section').find('input[type="radio"][value=""]').prop('checked', true);
1503
+ });
1504
+
1505
+ //Submit the form on popup click
1506
+ jQuery(document).on('click', '.submit-the-form', function (e) {
1507
+ e.preventDefault();
1508
+ // Triggger the click event on the quiz form's submit button.
1509
+ jQuery('.qsm-submit-btn').trigger('click');
1510
+ jQuery('#modal-3').removeClass('is-open');
1511
+ });
1512
+
1513
+ jQuery('.pagetime-goto-nextpage').click(function (e) {
1514
+ e.preventDefault();
1515
+ var quiz_id = jQuery(this).data('quiz_id');
1516
+ QSM.nextPage(quiz_id);
1517
+ var $container = jQuery('#quizForm' + quiz_id).closest('.qmn_quiz_container');
1518
+ qsmScrollTo($container);
1519
+ });
1520
+
1521
+ jQuery(document).on('keyup', '.mlwPhoneNumber', function (e) {
1522
+ this.value = this.value.replace(/[^- +()0-9\.]/g, '');
1523
+ });
1524
+
1525
+ jQuery(document).on('click', '.qsm_social_share_link', function (e) {
1526
+ e.preventDefault();
1527
+ var network = jQuery(this).attr('data-network');
1528
+ var share_url = jQuery(this).attr('data-link');
1529
+ var social_text = jQuery(this).attr('data-text');
1530
+ var social_id = jQuery(this).attr('data-id');
1531
+ var url = '';
1532
+ if (network == 'facebook') {
1533
+ url = "https://www.facebook.com/dialog/feed?" + "display=popup&" + "app_id=" + social_id +
1534
+ "&" + "link=" + encodeURIComponent(share_url) + "&" + "name=" + social_text;
1535
+ }
1536
+ if (network == 'twitter') {
1537
+ url = "https://twitter.com/intent/tweet?text=" + social_text;
1538
+ }
1539
+ var sTop = window.screen.height / 2 - (218);
1540
+ var sLeft = window.screen.width / 2 - (313);
1541
+ var sqShareOptions = "height=400,width=580,toolbar=0,status=0,location=0,menubar=0,directories=0,scrollbars=0,top=" + sTop + ",left=" + sLeft;
1542
+ window.open(url, "Share", sqShareOptions);
1543
+ return false;
1544
+ });
1545
+ });
1546
+
1547
+ // captcha question type
1548
+ var mlw_code;
1549
+ jQuery(document).ready(function() {
1550
+ let captchaElement = jQuery('#mlw_code_captcha');
1551
+ if (captchaElement.length !== 0){
1552
+ mlw_code = '';
1553
+ var mlw_chars = '0123456789ABCDEFGHIJKL!@#$%^&*()MNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
1554
+ var mlw_code_length = 5;
1555
+ for (var i=0; i<mlw_code_length; i++) {
1556
+ var rnum = Math.floor(Math.random() * mlw_chars.length);
1557
+ mlw_code += mlw_chars.substring(rnum,rnum+1);
1558
+ }
1559
+ var mlw_captchaCTX = document.getElementById('mlw_captcha').getContext('2d');
1560
+ mlw_captchaCTX.font = 'normal 24px Verdana';
1561
+ mlw_captchaCTX.strokeStyle = '#000000';
1562
+ mlw_captchaCTX.clearRect(0,0,100,50);
1563
+ mlw_captchaCTX.strokeText(mlw_code,10,30,70);
1564
+ mlw_captchaCTX.textBaseline = 'middle';
1565
+ document.getElementById('mlw_code_captcha').value = mlw_code;
1566
+ }
1567
+ });
1568
+
1569
+ var qsmTimerInterval = setInterval(qmnTimeTakenTimer, 1000);
1570
+ var quizType = 'default';
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: 7.3.7
6
  * Author: ExpressTech
7
  * Author URI: https://quizandsurveymaster.com/
8
  * Plugin URI: https://expresstech.io/
9
  * Text Domain: quiz-master-next
10
  *
11
  * @author QSM Team
12
- * @version 7.3.7
13
  * @package QSM
14
  */
15
 
@@ -38,14 +38,13 @@ define( 'QSM_PLUGIN_TXTDOMAIN', 'quiz-master-next' );
38
  */
39
  class MLWQuizMasterNext {
40
 
41
-
42
  /**
43
  * QSM Version Number
44
  *
45
  * @var string
46
  * @since 4.0.0
47
  */
48
- public $version = '7.3.7';
49
 
50
  /**
51
  * QSM Alert Manager Object
@@ -111,6 +110,14 @@ class MLWQuizMasterNext {
111
  */
112
  public $migrationHelper;
113
 
 
 
 
 
 
 
 
 
114
  /**
115
  * Main Construct Function
116
  *
@@ -542,8 +549,33 @@ class MLWQuizMasterNext {
542
  }
543
  }
544
 
 
545
  }
546
 
547
  global $mlwQuizMasterNext;
548
  $mlwQuizMasterNext = new MLWQuizMasterNext();
549
  register_activation_hook( __FILE__, array( 'QSM_Install', 'install' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /**
3
  * Plugin Name: Quiz And Survey Master
4
  * Description: Easily and quickly add quizzes and surveys to your website.
5
+ * Version: 7.3.8
6
  * Author: ExpressTech
7
  * Author URI: https://quizandsurveymaster.com/
8
  * Plugin URI: https://expresstech.io/
9
  * Text Domain: quiz-master-next
10
  *
11
  * @author QSM Team
12
+ * @version 7.3.8
13
  * @package QSM
14
  */
15
 
38
  */
39
  class MLWQuizMasterNext {
40
 
 
41
  /**
42
  * QSM Version Number
43
  *
44
  * @var string
45
  * @since 4.0.0
46
  */
47
+ public $version = '7.3.8';
48
 
49
  /**
50
  * QSM Alert Manager Object
110
  */
111
  public $migrationHelper;
112
 
113
+ /**
114
+ * Holds quiz_data
115
+ *
116
+ * @var object
117
+ * @since 7.3.8
118
+ */
119
+ public $quiz = array();
120
+
121
  /**
122
  * Main Construct Function
123
  *
549
  }
550
  }
551
 
552
+
553
  }
554
 
555
  global $mlwQuizMasterNext;
556
  $mlwQuizMasterNext = new MLWQuizMasterNext();
557
  register_activation_hook( __FILE__, array( 'QSM_Install', 'install' ) );
558
+
559
+ /**
560
+ * Displays QSM Admin bar menu
561
+ *
562
+ * @return void
563
+ * @since 7.3.8
564
+ */
565
+ function qsm_edit_quiz_admin_option() {
566
+ global $wp_admin_bar, $wpdb;
567
+ if ( 'qsm_quiz' == get_post_type() ) {
568
+ $get_qsm_post_id = get_the_ID();
569
+ $get_qsm_quiz_id = $wpdb->get_results( "SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id=$get_qsm_post_id" );
570
+ $wp_admin_bar->add_node(
571
+ array(
572
+ 'id' => 'edit-quiz',
573
+ 'title' => '<span class="ab-icon dashicons dashicons-edit"></span><span class="ab-label">' . __( 'Edit Quiz', 'quiz-master-next' ) . '</span>',
574
+ 'href' => admin_url() . 'admin.php?page=mlw_quiz_options&quiz_id=' . $get_qsm_quiz_id[0]->meta_value,
575
+
576
+ )
577
+ );
578
+ }
579
+ }
580
+
581
+ add_action( 'admin_bar_menu', 'qsm_edit_quiz_admin_option', 999 );
php/admin/admin-results-page.php CHANGED
@@ -23,9 +23,11 @@ function qsm_generate_admin_results_page() {
23
 
24
  ?>
25
  <div class="wrap">
26
- <div style="display:flex;justify-content:space-between;align-items:center;">
27
- <h2 style="font-size:2em"><?php esc_html_e( 'Quiz Results', 'quiz-master-next' ); ?></h2>
28
- <span id="results-screen-option-button" class="button">Screen Options</span>
 
 
29
  </div>
30
  <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
31
  <?php qsm_show_adverts(); ?>
@@ -314,10 +316,10 @@ if ( isset($_POST["results-screen_option_nonce"]) && wp_verify_nonce( sanitize_t
314
  $results_screen_option['phone'] = isset($_POST['phone']) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : "0";
315
  $results_screen_option['ip_address'] = isset($_POST['ip_address']) ? sanitize_text_field( wp_unslash( $_POST['ip_address'] ) ) : "0";
316
  //set screen option as user meta
317
- add_user_meta( $user_id, 'results_screen_option',$results_screen_option, true);
318
  } else {
319
- $results_screen_option = get_user_meta( $user_id );
320
- $results_screen_option = ! empty( $results_screen_option['results_screen_option'] ) ? $results_screen_option['results_screen_option'][0] : '';
321
  if ( empty($results_screen_option) ) {
322
  $results_screen_option = array(
323
  'page_url' => '0',
23
 
24
  ?>
25
  <div class="wrap">
26
+ <div>
27
+ <h2 id="result_details">
28
+ <?php esc_html_e( 'Quiz Results', 'quiz-master-next' ); ?>
29
+ <span id="results-screen-option-button" class="button">Screen Options</span>
30
+ </h2>
31
  </div>
32
  <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
33
  <?php qsm_show_adverts(); ?>
316
  $results_screen_option['phone'] = isset($_POST['phone']) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : "0";
317
  $results_screen_option['ip_address'] = isset($_POST['ip_address']) ? sanitize_text_field( wp_unslash( $_POST['ip_address'] ) ) : "0";
318
  //set screen option as user meta
319
+ add_user_meta( $user_id, 'results_screen_option',$results_screen_option, true );
320
  } else {
321
+ $results_screen_option = get_user_meta( $user_id, 'results_screen_option', true );
322
+ $results_screen_option = ! empty( $results_screen_option ) ? $results_screen_option : '';
323
  if ( empty($results_screen_option) ) {
324
  $results_screen_option = array(
325
  'page_url' => '0',
php/admin/functions.php CHANGED
@@ -567,6 +567,10 @@ function qsm_create_new_quiz_wizard() {
567
  'option_name' => __( 'Disable scroll on next and previous button click?', 'quiz-master-next' ),
568
  'value' => 0,
569
  ),
 
 
 
 
570
  );
571
  $quiz_setting_option = apply_filters( 'qsm_quiz_wizard_settings_option', $quiz_setting_option );
572
  if ( $quiz_setting_option ) {
567
  'option_name' => __( 'Disable scroll on next and previous button click?', 'quiz-master-next' ),
568
  'value' => 0,
569
  ),
570
+ 'disable_first_page' => array(
571
+ 'option_name' => __( 'Disable first page on quiz', 'quiz-master-next' ),
572
+ 'value' => 0,
573
+ ),
574
  );
575
  $quiz_setting_option = apply_filters( 'qsm_quiz_wizard_settings_option', $quiz_setting_option );
576
  if ( $quiz_setting_option ) {
php/admin/options-page-email-tab.php CHANGED
@@ -17,7 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) {
17
  */
18
  function qsm_settings_email_tab() {
19
  global $mlwQuizMasterNext;
20
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Emails', 'quiz-master-next' ), 'qsm_options_emails_tab_content', 'emails');
21
  }
22
  add_action( 'plugins_loaded', 'qsm_settings_email_tab', 5 );
23
 
@@ -28,7 +28,6 @@ add_action( 'plugins_loaded', 'qsm_settings_email_tab', 5 );
28
  * @since 4.4.0
29
  */
30
  function qsm_options_emails_tab_content() {
31
- global $wpdb;
32
  global $mlwQuizMasterNext;
33
 
34
  $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0;
@@ -41,14 +40,6 @@ function qsm_options_emails_tab_content() {
41
  );
42
  wp_localize_script( 'qsm_admin_js', 'qsmEmailsObject', $js_data );
43
 
44
- $categories = array();
45
- $enabled = get_option( 'qsm_multiple_category_enabled' );
46
- if ( $enabled && 'cancelled' !== $enabled ) {
47
- $query = $wpdb->prepare( "SELECT name FROM {$wpdb->prefix}terms WHERE term_id IN ( SELECT DISTINCT term_id FROM {$wpdb->prefix}mlw_question_terms WHERE quiz_id = %d ) ORDER BY name ASC", $quiz_id );
48
- } else {
49
- $query = $wpdb->prepare( "SELECT DISTINCT category FROM {$wpdb->prefix}mlw_questions WHERE category <> '' AND quiz_id = %d", $quiz_id );
50
- }
51
- $categories = $wpdb->get_results( $query, ARRAY_N );
52
  ?>
53
 
54
  <!-- Emails Section -->
@@ -68,7 +59,7 @@ function qsm_options_emails_tab_content() {
68
  </section>
69
 
70
  <!-- Templates -->
71
- <?php add_action('admin_footer', 'qsm_options_emails_tab_template'); ?>
72
  <!--Template popup-->
73
  <div class="qsm-popup qsm-popup-slide" id="show-all-variable" aria-hidden="false">
74
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close="">
@@ -87,31 +78,31 @@ function qsm_options_emails_tab_content() {
87
  $variable_list['Core']['%QUESTIONS_ANSWERS_EMAIL%'] = __( 'Shows the question, the answer provided by user, and the correct answer.', 'quiz-master-next' );
88
  unset( $variable_list['Core']['%FACEBOOK_SHARE%'] );
89
  unset( $variable_list['Core']['%TWITTER_SHARE%'] );
90
- //filter to add or remove variables from variable list for email tab
91
  $variable_list = apply_filters( 'qsm_text_variable_list_email', $variable_list );
92
 
93
  if ( $variable_list ) {
94
- //sort $variable list for backward compatibility
95
  foreach ( $variable_list as $variable_name => $variable_value ) {
96
  if ( ! is_array( $variable_value ) ) {
97
- $variable_list['Other Variables'][ $variable_name ] = $variable_value ;
98
  }
99
  }
100
  foreach ( $variable_list as $category_name => $category_variables ) {
101
- //check if the $category_variables is an array for backward compatibility
102
  if ( is_array( $category_variables ) ) {
103
  ?>
104
- <div><h2><?php echo esc_attr($category_name);?></h2></div>
105
  <?php
106
  foreach ( $category_variables as $variable_key => $variable ) {
107
  ?>
108
  <div class="popup-template-span-wrap">
109
  <span class="qsm-text-template-span">
110
- <span class="button button-default template-variable"><?php echo esc_attr($variable_key); ?></span>
111
  <span class="button click-to-copy">Click to Copy</span>
112
  <span class="temp-var-seperator">
113
  <span class="dashicons dashicons-editor-help qsm-tooltips-icon">
114
- <span class="qsm-tooltips"><?php echo esc_attr($variable); ?></span>
115
  </span>
116
  </span>
117
  </span>
@@ -130,7 +121,7 @@ function qsm_options_emails_tab_content() {
130
  </div>
131
  </div>
132
  </div>
133
- <?php
134
  }
135
 
136
  /**
@@ -138,8 +129,18 @@ function qsm_options_emails_tab_content() {
138
  *
139
  * @since 7.3.5
140
  */
141
- function qsm_options_emails_tab_template(){ ?>
142
-
 
 
 
 
 
 
 
 
 
 
143
  <script type="text/template" id="tmpl-email">
144
  <div class="qsm-email">
145
  <header class="qsm-email-header">
@@ -177,16 +178,17 @@ function qsm_options_emails_tab_template(){ ?>
177
  <script type="text/template" id="tmpl-email-condition">
178
  <div class="email-condition">
179
  <button class="delete-condition-button"><span class="dashicons dashicons-trash"></span></button>
180
- <?php if ( ! empty( $categories ) ) { ?>
181
- <select class="email-condition-category">
182
- <option value="" <# if (data.category == '') { #>selected<# } #>><?php esc_html_e( 'Quiz', 'quiz-master-next' ); ?></option>
183
- <option value="" disabled><?php esc_html_e( '---Select Category---', 'quiz-master-next' ); ?></option>
184
- <?php foreach ( $categories as $cat ) { ?>
185
- <option value="<?php echo esc_attr($cat[0]); ?>" <# if (data.category == '<?php echo esc_attr($cat[0]); ?>') { #>selected<# } #>><?php echo esc_attr($cat[0]); ?></option>
186
- <?php } ?>
187
- <?php do_action( 'qsm_results_page_condition_criteria' ); ?>
188
- </select>
189
- <?php } ?>
 
190
  <select class="email-condition-criteria">
191
  <option value="points" <# if (data.criteria == 'points') { #>selected<# } #>><?php esc_html_e( 'Total points earned', 'quiz-master-next' ); ?></option>
192
  <option value="score" <# if (data.criteria == 'score') { #>selected<# } #>><?php esc_html_e( 'Correct score percentage', 'quiz-master-next' ); ?></option>
@@ -207,6 +209,6 @@ function qsm_options_emails_tab_template(){ ?>
207
  </div>
208
  </script>
209
 
210
- <?php
211
  }
212
- ?>
17
  */
18
  function qsm_settings_email_tab() {
19
  global $mlwQuizMasterNext;
20
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Emails', 'quiz-master-next' ), 'qsm_options_emails_tab_content', 'emails' );
21
  }
22
  add_action( 'plugins_loaded', 'qsm_settings_email_tab', 5 );
23
 
28
  * @since 4.4.0
29
  */
30
  function qsm_options_emails_tab_content() {
 
31
  global $mlwQuizMasterNext;
32
 
33
  $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0;
40
  );
41
  wp_localize_script( 'qsm_admin_js', 'qsmEmailsObject', $js_data );
42
 
 
 
 
 
 
 
 
 
43
  ?>
44
 
45
  <!-- Emails Section -->
59
  </section>
60
 
61
  <!-- Templates -->
62
+ <?php add_action( 'admin_footer', 'qsm_options_emails_tab_template' ); ?>
63
  <!--Template popup-->
64
  <div class="qsm-popup qsm-popup-slide" id="show-all-variable" aria-hidden="false">
65
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close="">
78
  $variable_list['Core']['%QUESTIONS_ANSWERS_EMAIL%'] = __( 'Shows the question, the answer provided by user, and the correct answer.', 'quiz-master-next' );
79
  unset( $variable_list['Core']['%FACEBOOK_SHARE%'] );
80
  unset( $variable_list['Core']['%TWITTER_SHARE%'] );
81
+ // filter to add or remove variables from variable list for email tab
82
  $variable_list = apply_filters( 'qsm_text_variable_list_email', $variable_list );
83
 
84
  if ( $variable_list ) {
85
+ // sort $variable list for backward compatibility
86
  foreach ( $variable_list as $variable_name => $variable_value ) {
87
  if ( ! is_array( $variable_value ) ) {
88
+ $variable_list['Other Variables'][ $variable_name ] = $variable_value;
89
  }
90
  }
91
  foreach ( $variable_list as $category_name => $category_variables ) {
92
+ // check if the $category_variables is an array for backward compatibility
93
  if ( is_array( $category_variables ) ) {
94
  ?>
95
+ <div><h2><?php echo esc_attr( $category_name ); ?></h2></div>
96
  <?php
97
  foreach ( $category_variables as $variable_key => $variable ) {
98
  ?>
99
  <div class="popup-template-span-wrap">
100
  <span class="qsm-text-template-span">
101
+ <span class="button button-default template-variable"><?php echo esc_attr( $variable_key ); ?></span>
102
  <span class="button click-to-copy">Click to Copy</span>
103
  <span class="temp-var-seperator">
104
  <span class="dashicons dashicons-editor-help qsm-tooltips-icon">
105
+ <span class="qsm-tooltips"><?php echo esc_attr( $variable ); ?></span>
106
  </span>
107
  </span>
108
  </span>
121
  </div>
122
  </div>
123
  </div>
124
+ <?php
125
  }
126
 
127
  /**
129
  *
130
  * @since 7.3.5
131
  */
132
+ function qsm_options_emails_tab_template() {
133
+ global $wpdb;
134
+ $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0;
135
+ $categories = array();
136
+ $enabled = get_option( 'qsm_multiple_category_enabled' );
137
+ if ( $enabled && 'cancelled' !== $enabled ) {
138
+ $query = $wpdb->prepare( "SELECT name FROM {$wpdb->prefix}terms WHERE term_id IN ( SELECT DISTINCT term_id FROM {$wpdb->prefix}mlw_question_terms WHERE quiz_id = %d ) ORDER BY name ASC", $quiz_id );
139
+ } else {
140
+ $query = $wpdb->prepare( "SELECT DISTINCT category FROM {$wpdb->prefix}mlw_questions WHERE category <> '' AND quiz_id = %d", $quiz_id );
141
+ }
142
+ $categories = $wpdb->get_results( $query, ARRAY_N );
143
+ ?>
144
  <script type="text/template" id="tmpl-email">
145
  <div class="qsm-email">
146
  <header class="qsm-email-header">
178
  <script type="text/template" id="tmpl-email-condition">
179
  <div class="email-condition">
180
  <button class="delete-condition-button"><span class="dashicons dashicons-trash"></span></button>
181
+ <select class="email-condition-category">
182
+ <option value="" <# if (data.category == '') { #>selected<# } #>><?php esc_html_e( 'Quiz', 'quiz-master-next' ); ?></option>
183
+ <option value="" disabled><?php esc_html_e( '---Select Category---', 'quiz-master-next' ); ?></option>
184
+ <?php if ( ! empty( $categories ) ) { ?>
185
+ <?php foreach ( $categories as $cat ) { ?>
186
+ <option value="<?php echo esc_attr( $cat[0] ); ?>" <# if (data.category == '<?php echo esc_attr( $cat[0] ); ?>') { #>selected<# } #>><?php echo esc_attr( $cat[0] ); ?></option>
187
+ <?php } ?>
188
+ <?php } else { ?>
189
+ <option value="" disabled><?php esc_html_e( 'No Categories Available', 'quiz-master-next' ); ?></option>
190
+ <?php } ?>
191
+ </select>
192
  <select class="email-condition-criteria">
193
  <option value="points" <# if (data.criteria == 'points') { #>selected<# } #>><?php esc_html_e( 'Total points earned', 'quiz-master-next' ); ?></option>
194
  <option value="score" <# if (data.criteria == 'score') { #>selected<# } #>><?php esc_html_e( 'Correct score percentage', 'quiz-master-next' ); ?></option>
209
  </div>
210
  </script>
211
 
212
+ <?php
213
  }
214
+ ?>
php/admin/options-page-questions-tab.php CHANGED
@@ -107,7 +107,8 @@ function qsm_options_questions_tab_content() {
107
  wp_localize_script( 'qsm_admin_js', 'qsmQuestionSettings', $json_data );
108
 
109
  // Load Question Types.
110
- $question_types = $mlwQuizMasterNext->pluginHelper->get_question_type_options();
 
111
 
112
  // Display warning if using competing options.
113
  $pagination = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'pagination' );
@@ -239,7 +240,7 @@ function qsm_options_questions_tab_content() {
239
  ),
240
  array(
241
  'question_type_id' => '6',
242
- 'description' => __( 'Displays a simple section on front end.', 'quiz-master-next' ),
243
  ),
244
  array(
245
  'question_type_id' => '7',
@@ -367,11 +368,19 @@ function qsm_options_questions_tab_content() {
367
  </label>
368
  <select name="question_type" id="question_type">
369
  <?php
370
- foreach ( $question_types as $type ) {
371
- if ( isset( $type['options']['add_separate_option_text'] ) && null !== $type['options']['add_separate_option_text'] ) {
372
- echo '<option disabled>---' . esc_html( $type['options']['add_separate_option_text'] ) . '---</option>';
373
- }
374
- echo '<option value="' . esc_attr( $type['slug'] ) . '">' . esc_html( $type['name'] ) . '</option>';
 
 
 
 
 
 
 
 
375
  }
376
  ?>
377
  </select>
@@ -403,7 +412,7 @@ function qsm_options_questions_tab_content() {
403
  'image' => __( 'Image Answers', 'quiz-master-next' ),
404
  ),
405
  'default' => 'text',
406
- 'show' => '0,1,2,4,13' . $show_change_answer_editor,
407
  // 'tooltip' => __('You can use text and rich answer for question answers.', 'quiz-master-next'),.
408
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/questions-tab/#Answer-Type',
409
  ),
@@ -428,6 +437,17 @@ function qsm_options_questions_tab_content() {
428
  'default' => 'random',
429
  'show' => '14' . $show_match_answer,
430
  ),
 
 
 
 
 
 
 
 
 
 
 
431
  );
432
  $simple_question_option = apply_filters( 'qsm_question_format_option', $simple_question_option );
433
  $keys = array_column( $simple_question_option, 'priority' );
107
  wp_localize_script( 'qsm_admin_js', 'qsmQuestionSettings', $json_data );
108
 
109
  // Load Question Types.
110
+ $question_types = $mlwQuizMasterNext->pluginHelper->get_question_type_options();
111
+ $question_types_categorized = $mlwQuizMasterNext->pluginHelper->categorize_question_types();
112
 
113
  // Display warning if using competing options.
114
  $pagination = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'pagination' );
240
  ),
241
  array(
242
  'question_type_id' => '6',
243
+ 'description' => __( 'Displays a simple section on front end. Description is mandatory. ', 'quiz-master-next' ),
244
  ),
245
  array(
246
  'question_type_id' => '7',
368
  </label>
369
  <select name="question_type" id="question_type">
370
  <?php
371
+ foreach ( $question_types_categorized as $category_name => $category_items ) {
372
+ ?>
373
+ <optgroup label="<?php echo esc_attr( $category_name ) ?>">
374
+ <?php
375
+ foreach ( $category_items as $type ) {
376
+ if ( isset( $type['options']['add_separate_option_text'] ) && null !== $type['options']['add_separate_option_text'] ) {
377
+ echo '<option disabled>---' . esc_html( $type['options']['add_separate_option_text'] ) . '---</option>';
378
+ }
379
+ echo '<option value="' . esc_attr( $type['slug'] ) . '">' . esc_html( $type['name'] ) . '</option>';
380
+ }
381
+ ?>
382
+ </optgroup>
383
+ <?php
384
  }
385
  ?>
386
  </select>
412
  'image' => __( 'Image Answers', 'quiz-master-next' ),
413
  ),
414
  'default' => 'text',
415
+ 'show' => '0,1,4,13' . $show_change_answer_editor,
416
  // 'tooltip' => __('You can use text and rich answer for question answers.', 'quiz-master-next'),.
417
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/questions-tab/#Answer-Type',
418
  ),
437
  'default' => 'random',
438
  'show' => '14' . $show_match_answer,
439
  ),
440
+ 'text-answer-editor' => array(
441
+ 'label' => __( 'Answers Type', 'quiz-master-next' ),
442
+ 'type' => 'select',
443
+ 'priority' => '4',
444
+ 'options' => array(
445
+ 'text' => __( 'Text Answers', 'quiz-master-next' ),
446
+ ),
447
+ 'default' => 'text',
448
+ 'show' => '2' . $show_change_answer_editor,
449
+ 'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/questions-tab/#Answer-Type',
450
+ ),
451
  );
452
  $simple_question_option = apply_filters( 'qsm_question_format_option', $simple_question_option );
453
  $keys = array_column( $simple_question_option, 'priority' );
php/admin/options-page-style-tab.php CHANGED
@@ -104,7 +104,7 @@ function qsm_options_styling_tab_content() {
104
  if ( isset( $_POST['save_theme_settings_nonce'], $_POST['settings'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['save_theme_settings_nonce'] ) ), 'save_theme_settings' ) ) {
105
  unset( $_POST['save_theme_settings_nonce'] );
106
  unset( $_POST['_wp_http_referer'] );
107
- $settings_array = array_map( 'sanitize_text_field', wp_unslash( $_POST['settings'] ) );
108
  $results = $mlwQuizMasterNext->theme_settings->update_quiz_theme_settings(
109
  $quiz_id,
110
  $saved_quiz_theme,
@@ -243,43 +243,47 @@ function qsm_options_styling_tab_content() {
243
  <div class="qsm-popup qsm-popup-slide qsm-theme-color-settings" id="qsm-theme-color-settings" aria-hidden="true">
244
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
245
  <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-2-title">
246
- <header class="qsm-popup__header">
247
- <h2 class="qsm-popup__title" id="modal-2-title">
248
- <?php esc_html_e( 'Customize Quiz Theme', 'quiz-master-next' ); ?>
249
- </h2>
250
- <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
251
- </header>
252
- <main class="qsm-popup__content" id="thme-color-settings-content">
253
- <form action="" method="post" class="qsm-theme-settings-frm">
254
  <?php wp_nonce_field( 'save_theme_settings', 'save_theme_settings_nonce' ); ?>
255
  <table class="form-table" style="width: 100%;">
256
  <?php
257
- $get_theme_settings = $mlwQuizMasterNext->theme_settings->get_active_theme_settings( $quiz_id, $saved_quiz_theme );
258
-
 
 
 
259
  if ( $get_theme_settings ) {
260
- $i = 0;
261
  foreach ( $get_theme_settings as $key => $theme_val ) {
 
 
 
262
  ?>
263
- <tr valign="top">
264
- <th scope="row" class="qsm-opt-tr">
265
- <label for="form_type"><?php echo esc_attr( $theme_val['label'] ); ?></label>
266
- <input type="hidden" name="settings[<?php echo esc_attr( $i ); ?>][label]"
267
- value="<?php echo esc_attr( $theme_val['label'] ); ?>">
268
- <input type="hidden" name="settings[<?php echo esc_attr( $i ); ?>][id]"
269
- value="<?php echo esc_attr( $theme_val['id'] ); ?>">
270
- <input type="hidden" name="settings[<?php echo esc_attr( $i ); ?>][type]" value="color">
271
- </th>
272
- <td>
273
- <input name="settings[<?php echo esc_attr( $i ); ?>][default]" type="text"
274
- value="<?php echo esc_attr( $theme_val['default'] ); ?>"
275
- data-default-color="<?php echo esc_attr( $theme_val['default'] ); ?>" class="my-color-field" />
276
- </td>
277
- </tr>
278
- <?php
279
- $i++;
280
  }
281
  } else {
282
- ?>
283
  <tr>
284
  <td colspan="2">
285
  <?php esc_html_e( 'No settings found', 'quiz-master-next' ); ?>
@@ -289,14 +293,14 @@ function qsm_options_styling_tab_content() {
289
  }
290
  ?>
291
  </table>
292
- </form>
293
- </main>
294
- <footer class="qsm-popup__footer">
295
- <button id="qsm-save-theme-settings"
296
- class="button button-primary"><?php esc_html_e( 'Save Settings', 'quiz-master-next' ); ?></button>
297
- <button class="button" data-micromodal-close
298
- aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
299
- </footer>
300
  </div>
301
  </div>
302
  </div>
@@ -317,7 +321,7 @@ function qsm_display_theme_settings() {
317
  if ( isset( $_POST['save_theme_settings_nonce'], $_POST['settings'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['save_theme_settings_nonce'] ) ), 'save_theme_settings' ) ) {
318
  unset( $_POST['save_theme_settings_nonce'] );
319
  unset( $_POST['_wp_http_referer'] );
320
- $settings_array = array_map( 'sanitize_text_field', wp_unslash( $_POST['settings'] ) );
321
  $results = $mlwQuizMasterNext->theme_settings->update_quiz_theme_settings( $quiz_id, $theme_id, $settings_array );
322
  ?>
323
  <div class="notice notice-success is-dismissible" style="margin-top:30px;">
104
  if ( isset( $_POST['save_theme_settings_nonce'], $_POST['settings'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['save_theme_settings_nonce'] ) ), 'save_theme_settings' ) ) {
105
  unset( $_POST['save_theme_settings_nonce'] );
106
  unset( $_POST['_wp_http_referer'] );
107
+ $settings_array = qsm_sanitize_rec_array( wp_unslash( $_POST['settings'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
108
  $results = $mlwQuizMasterNext->theme_settings->update_quiz_theme_settings(
109
  $quiz_id,
110
  $saved_quiz_theme,
243
  <div class="qsm-popup qsm-popup-slide qsm-theme-color-settings" id="qsm-theme-color-settings" aria-hidden="true">
244
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
245
  <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-2-title">
246
+ <form action="" method="post" class="qsm-theme-settings-frm">
247
+ <header class="qsm-popup__header">
248
+ <h2 class="qsm-popup__title" id="modal-2-title">
249
+ <?php esc_html_e( 'Customize Quiz Theme', 'quiz-master-next' ); ?>
250
+ </h2>
251
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
252
+ </header>
253
+ <main class="qsm-popup__content" id="thme-color-settings-content">
254
  <?php wp_nonce_field( 'save_theme_settings', 'save_theme_settings_nonce' ); ?>
255
  <table class="form-table" style="width: 100%;">
256
  <?php
257
+ global $wpdb;
258
+ $get_theme_settings = $mlwQuizMasterNext->theme_settings->get_active_theme_settings( $quiz_id, $saved_quiz_theme );
259
+ $get_theme_default_settings = $wpdb->get_var( $wpdb->prepare( "SELECT default_settings from wp_mlw_themes WHERE id = %d", $saved_quiz_theme ) );
260
+ $get_theme_settings = maybe_unserialize($get_theme_settings);
261
+ $get_theme_default_settings = maybe_unserialize($get_theme_default_settings);
262
  if ( $get_theme_settings ) {
 
263
  foreach ( $get_theme_settings as $key => $theme_val ) {
264
+ if ( '' === $theme_val ) {
265
+ $theme_val = $get_theme_default_settings[ $key ];
266
+ }
267
  ?>
268
+ <tr valign="top">
269
+ <th scope="row" class="qsm-opt-tr">
270
+ <label for="form_type"><?php echo esc_attr( $theme_val['label'] ); ?></label>
271
+ <input type="hidden" name="settings[<?php echo esc_attr( $key ); ?>][label]"
272
+ value="<?php echo esc_attr( $theme_val['label'] ); ?>">
273
+ <input type="hidden" name="settings[<?php echo esc_attr( $key ); ?>][id]"
274
+ value="<?php echo esc_attr( $theme_val['id'] ); ?>">
275
+ <input type="hidden" name="settings[<?php echo esc_attr( $key ); ?>][type]" value="color">
276
+ </th>
277
+ <td>
278
+ <input name="settings[<?php echo esc_attr( $key ); ?>][default]" type="text"
279
+ value="<?php echo esc_attr( $theme_val['default'] ); ?>"
280
+ data-default-color="<?php echo esc_attr( $theme_val['default'] ); ?>" class="my-color-field" />
281
+ </td>
282
+ </tr>
283
+ <?php
 
284
  }
285
  } else {
286
+ ?>
287
  <tr>
288
  <td colspan="2">
289
  <?php esc_html_e( 'No settings found', 'quiz-master-next' ); ?>
293
  }
294
  ?>
295
  </table>
296
+ </main>
297
+ <footer class="qsm-popup__footer">
298
+ <button type="submit" id="qsm-save-theme-settings"
299
+ class="button button-primary"><?php esc_html_e( 'Save Settings', 'quiz-master-next' ); ?></button>
300
+ <button class="button" data-micromodal-close
301
+ aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
302
+ </footer>
303
+ </form>
304
  </div>
305
  </div>
306
  </div>
321
  if ( isset( $_POST['save_theme_settings_nonce'], $_POST['settings'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['save_theme_settings_nonce'] ) ), 'save_theme_settings' ) ) {
322
  unset( $_POST['save_theme_settings_nonce'] );
323
  unset( $_POST['_wp_http_referer'] );
324
+ $settings_array = qsm_sanitize_rec_array( wp_unslash( $_POST['settings'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
325
  $results = $mlwQuizMasterNext->theme_settings->update_quiz_theme_settings( $quiz_id, $theme_id, $settings_array );
326
  ?>
327
  <div class="notice notice-success is-dismissible" style="margin-top:30px;">
php/admin/quiz-options-page.php CHANGED
@@ -98,9 +98,9 @@ function qsm_generate_quiz_options() {
98
  wp_reset_postdata();
99
  }
100
  ?>
101
- <div class="wrap">
102
- <div class='mlw_quiz_options'>
103
- <h1 style="margin-bottom: 10px;">
104
  <?php echo wp_kses_post( $quiz_name ); ?>
105
  <?php if ( 'draft' === $post_status ) : ?>
106
  <form method="POST" action="">
98
  wp_reset_postdata();
99
  }
100
  ?>
101
+ <div class="wrap" id="mlw_quiz_wrap">
102
+ <div class='mlw_quiz_options' id="mlw_quiz_options">
103
+ <h1 id="qsm_title_quiz" style="margin-bottom: 10px;">
104
  <?php echo wp_kses_post( $quiz_name ); ?>
105
  <?php if ( 'draft' === $post_status ) : ?>
106
  <form method="POST" action="">
php/admin/settings-page.php CHANGED
@@ -125,6 +125,7 @@ class QMNGlobalSettingsPage {
125
  add_settings_field( 'deselect-answer', __( 'Deselect Answer', 'quiz-master-next' ), array( $this, 'qsm_global_deselect_answer' ), 'qsm_default_global_option', 'qmn-global-section' );
126
  add_settings_field( 'disable-description-on-quiz-result-page', __( 'Disable description on quiz result page?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_description_on_quiz_result_page' ), 'qsm_default_global_option', 'qmn-global-section' );
127
  add_settings_field( 'disable-scroll-on-next-and-previous-button-click', __( 'Disable scroll on next and previous button click?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_scroll_on_next_and_previous_button_click' ), 'qsm_default_global_option', 'qmn-global-section' );
 
128
  add_settings_field( 'quiz-animation', __( 'Quiz Animation', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_animation' ), 'qsm_default_global_option', 'qmn-global-section' );
129
  add_settings_field( 'logo-url', __( 'Logo URL', 'quiz-master-next' ), array( $this, 'qsm_global_logo_url' ), 'qsm_default_global_option', 'qmn-global-section' );
130
  add_settings_field( 'preferred_date_format', __( 'Preferred Date Format', 'quiz-master-next' ), array( $this, 'preferred_date_format' ), 'qsm_default_global_option', 'qmn-global-section' );
@@ -1019,6 +1020,24 @@ class QMNGlobalSettingsPage {
1019
  </fieldset>';
1020
  }
1021
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022
  /**
1023
  * Generates Quiz Global Field For Quiz Animation
1024
  *
125
  add_settings_field( 'deselect-answer', __( 'Deselect Answer', 'quiz-master-next' ), array( $this, 'qsm_global_deselect_answer' ), 'qsm_default_global_option', 'qmn-global-section' );
126
  add_settings_field( 'disable-description-on-quiz-result-page', __( 'Disable description on quiz result page?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_description_on_quiz_result_page' ), 'qsm_default_global_option', 'qmn-global-section' );
127
  add_settings_field( 'disable-scroll-on-next-and-previous-button-click', __( 'Disable scroll on next and previous button click?', 'quiz-master-next' ), array( $this, 'qsm_global_disable_scroll_on_next_and_previous_button_click' ), 'qsm_default_global_option', 'qmn-global-section' );
128
+ add_settings_field( 'disable-first-page', __( 'Disable first page on quiz', 'quiz-master-next' ), array( $this, 'qsm_global_disable_first_page' ), 'qsm_default_global_option', 'qmn-global-section' );
129
  add_settings_field( 'quiz-animation', __( 'Quiz Animation', 'quiz-master-next' ), array( $this, 'qsm_global_quiz_animation' ), 'qsm_default_global_option', 'qmn-global-section' );
130
  add_settings_field( 'logo-url', __( 'Logo URL', 'quiz-master-next' ), array( $this, 'qsm_global_logo_url' ), 'qsm_default_global_option', 'qmn-global-section' );
131
  add_settings_field( 'preferred_date_format', __( 'Preferred Date Format', 'quiz-master-next' ), array( $this, 'preferred_date_format' ), 'qsm_default_global_option', 'qmn-global-section' );
1020
  </fieldset>';
1021
  }
1022
 
1023
+ /**
1024
+ * Generates Quiz Global Field For Disable First page
1025
+ *
1026
+ * @since 4.1.0
1027
+ * @return void
1028
+ */
1029
+ public function qsm_global_disable_first_page() {
1030
+ global $globalQuizsetting;
1031
+ $qsm_disable_first_page = (isset($globalQuizsetting['disable_first_page']) && '' !== $globalQuizsetting['disable_first_page'] ? $globalQuizsetting['disable_first_page'] : "0");
1032
+ echo '<fieldset class="buttonset buttonset-hide" >
1033
+ <input type="radio" id="disable_first_page-1" name="qsm-quiz-settings[disable_first_page]" value="1" '. checked( $qsm_disable_first_page, '1', false ) .'>
1034
+ <label for="disable_first_page-1">Yes</label><br>
1035
+ <input type="radio" id="disable_first_page-0" name="qsm-quiz-settings[disable_first_page]" value="0" '. checked( $qsm_disable_first_page, '0', false ) .'>
1036
+ <label for="disable_first_page-0">No</label><br>
1037
+ </fieldset>';
1038
+ }
1039
+
1040
+
1041
  /**
1042
  * Generates Quiz Global Field For Quiz Animation
1043
  *
php/classes/class-qmn-plugin-helper.php CHANGED
@@ -12,7 +12,6 @@ if ( ! defined( 'ABSPATH' ) ) {
12
  */
13
  class QMNPluginHelper {
14
 
15
-
16
  /**
17
  * Addon Page tabs array
18
  *
@@ -322,7 +321,7 @@ class QMNPluginHelper {
322
  if ( is_null( $save_edit_function ) ) {
323
  $save_edit_function = '';
324
  }
325
- $new_type = array(
326
  'name' => $name,
327
  'display' => $display_function,
328
  'review' => $review_function,
@@ -332,7 +331,7 @@ class QMNPluginHelper {
332
  'slug' => $slug,
333
  'options' => $options,
334
  );
335
- $this->question_types[] = $new_type;
336
  }
337
 
338
  /**
@@ -355,6 +354,15 @@ class QMNPluginHelper {
355
  return $type_array;
356
  }
357
 
 
 
 
 
 
 
 
 
 
358
  public function get_question_type_edit_fields() {
359
  $type_array = array();
360
  foreach ( $this->question_types as $type ) {
@@ -393,10 +401,21 @@ class QMNPluginHelper {
393
  array( $question->answer_six, $question->answer_six_points, $mlw_answer_array_correct[5] ),
394
  );
395
  }
 
396
  if ( 2 === intval( $quiz_options->randomness_order ) || 3 === intval( $quiz_options->randomness_order ) ) {
397
  shuffle( $answers );
398
  update_post_meta( $question_id, 'qsm_random_quetion_answer', $answers );
399
  }
 
 
 
 
 
 
 
 
 
 
400
  /**
401
  * Filter Answers of specific question before display
402
  */
@@ -624,11 +643,11 @@ class QMNPluginHelper {
624
  * @param string $function The function that displays the tab's content
625
  * @return void
626
  */
627
- public function register_quiz_settings_tabs( $title, $function, $slug = "" ) {
628
- if ( "" === $slug ) {
629
  $slug = strtolower( str_replace( ' ', '-', $title ) );
630
  }
631
- $new_tab = array(
632
  'title' => $title,
633
  'function' => $function,
634
  'slug' => $slug,
@@ -820,7 +839,9 @@ class QMNPluginHelper {
820
  $simple_answer = "<span style='color:#808080;display:block;margin-bottom:5px;'>&#8226;&nbsp;";
821
  $html = str_replace( '<br/>', '<br>', $html );
822
  $html = str_replace( '<br />', '<br>', $html );
 
823
  $html = str_replace( "<span class='qmn_user_incorrect_answer'>", "<span style='color:red'>&#x2715; ", $html );
 
824
  $html = str_replace( "<span class='qmn_user_correct_answer'>", "<span style='color:green'>&#10003; ", $html );
825
  $html = str_replace( '<span class="qsm-text-wrong-option qmn_image_option">', "$incorrect_answer ", $html );
826
  $html = str_replace( '<span class="qsm-text-correct-option qmn_image_option">', "$correct_answer ", $html );
@@ -836,4 +857,36 @@ class QMNPluginHelper {
836
 
837
  return $html;
838
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
839
  }
12
  */
13
  class QMNPluginHelper {
14
 
 
15
  /**
16
  * Addon Page tabs array
17
  *
321
  if ( is_null( $save_edit_function ) ) {
322
  $save_edit_function = '';
323
  }
324
+ $new_type = array(
325
  'name' => $name,
326
  'display' => $display_function,
327
  'review' => $review_function,
331
  'slug' => $slug,
332
  'options' => $options,
333
  );
334
+ $this->question_types[ $slug ] = $new_type;
335
  }
336
 
337
  /**
354
  return $type_array;
355
  }
356
 
357
+ /**
358
+ *
359
+ */
360
+ public function set_question_type_meta( $type_id, $meta_key, $meta_value ) {
361
+
362
+ $this->question_types[ $type_id ][ $meta_key ] = $meta_value;
363
+
364
+ }
365
+
366
  public function get_question_type_edit_fields() {
367
  $type_array = array();
368
  foreach ( $this->question_types as $type ) {
401
  array( $question->answer_six, $question->answer_six_points, $mlw_answer_array_correct[5] ),
402
  );
403
  }
404
+ $answers_original = $answers;
405
  if ( 2 === intval( $quiz_options->randomness_order ) || 3 === intval( $quiz_options->randomness_order ) ) {
406
  shuffle( $answers );
407
  update_post_meta( $question_id, 'qsm_random_quetion_answer', $answers );
408
  }
409
+
410
+ // convert answer array into key value pair
411
+ $answers_kvpair = array();
412
+ foreach ( $answers as $answer_item ) {
413
+ $key = array_search( $answer_item, $answers_original, true );
414
+ $answers_kvpair[ $key ] = $answer_item;
415
+ }
416
+ unset( $answer_item );
417
+ $answers = $answers_kvpair;
418
+
419
  /**
420
  * Filter Answers of specific question before display
421
  */
643
  * @param string $function The function that displays the tab's content
644
  * @return void
645
  */
646
+ public function register_quiz_settings_tabs( $title, $function, $slug = '' ) {
647
+ if ( '' === $slug ) {
648
  $slug = strtolower( str_replace( ' ', '-', $title ) );
649
  }
650
+ $new_tab = array(
651
  'title' => $title,
652
  'function' => $function,
653
  'slug' => $slug,
839
  $simple_answer = "<span style='color:#808080;display:block;margin-bottom:5px;'>&#8226;&nbsp;";
840
  $html = str_replace( '<br/>', '<br>', $html );
841
  $html = str_replace( '<br />', '<br>', $html );
842
+ $html = str_replace( '<span class="qmn_user_incorrect_answer">', "<span style='color:red'>&#x2715; ", $html );
843
  $html = str_replace( "<span class='qmn_user_incorrect_answer'>", "<span style='color:red'>&#x2715; ", $html );
844
+ $html = str_replace( '<span class="qmn_user_correct_answer">', "<span style='color:green'>&#10003; ", $html );
845
  $html = str_replace( "<span class='qmn_user_correct_answer'>", "<span style='color:green'>&#10003; ", $html );
846
  $html = str_replace( '<span class="qsm-text-wrong-option qmn_image_option">', "$incorrect_answer ", $html );
847
  $html = str_replace( '<span class="qsm-text-correct-option qmn_image_option">', "$correct_answer ", $html );
857
 
858
  return $html;
859
  }
860
+
861
+ /** */
862
+ public function categorize_question_types() {
863
+ $question_type_categorized = array();
864
+ $question_type_others = array();
865
+ $question_type_uncategorized = array();
866
+ foreach ( $this->question_types as $question_type ) {
867
+ $is_categorized = isset( $question_type ['category'] ) && '' !== $question_type ['category'];
868
+ if ( $is_categorized ) {
869
+ if ( 'others' === mb_strtolower( $question_type ['category'] ) ) {
870
+ $question_type_others[ $question_type ['category'] ] [ $question_type['slug'] ] = array(
871
+ 'slug' => $question_type['slug'],
872
+ 'name' => $question_type['name'],
873
+ );
874
+ } else {
875
+ $question_type_categorized[ $question_type ['category'] ] [ $question_type['slug'] ] = array(
876
+ 'slug' => $question_type['slug'],
877
+ 'name' => $question_type['name'],
878
+ );
879
+ }
880
+ } else {
881
+ $question_type_uncategorized['uncategorized'][ $question_type['slug'] ] = array(
882
+ 'slug' => $question_type['slug'],
883
+ 'name' => $question_type['name'],
884
+ );
885
+
886
+ }
887
+ }
888
+ $question_type_categorized = array_merge( $question_type_categorized, $question_type_others );
889
+ $question_type_categorized = array_merge( $question_type_categorized, $question_type_uncategorized );
890
+ return $question_type_categorized;
891
+ }
892
  }
php/classes/class-qmn-quiz-manager.php CHANGED
@@ -113,7 +113,7 @@ class QMNQuizManager {
113
  $json = array();
114
  if ( ! isset( $_FILES['file'] ) ) {
115
  $json['type'] = 'error';
116
- $json['message'] = __( 'File is not uploaded', 'quiz-master-next' );
117
  echo wp_json_encode( $json );
118
  exit;
119
  }
@@ -149,12 +149,17 @@ class QMNQuizManager {
149
  include_once ABSPATH . 'wp-admin/includes/image.php';
150
  $attach_data = wp_generate_attachment_metadata( $attach_id, $movefile['file'] );
151
  wp_update_attachment_metadata( $attach_id, $attach_data );
 
 
 
 
 
 
 
 
 
 
152
  }
153
- $json['type'] = 'success';
154
- $json['message'] = __( 'File uploaded successfully', 'quiz-master-next' );
155
- $json['file_url'] = $movefile['url'];
156
- $json['file_path'] = basename( $movefile['url'] );
157
- echo wp_json_encode( $json );
158
  } else {
159
  $json['type'] = 'error';
160
  $json['message'] = $movefile['error'];
@@ -162,7 +167,7 @@ class QMNQuizManager {
162
  }
163
  } else {
164
  $json['type'] = 'error';
165
- $json['message'] = __( 'File type is not supported', 'quiz-master-next' );
166
  echo wp_json_encode( $json );
167
  }
168
  exit;
@@ -173,19 +178,18 @@ class QMNQuizManager {
173
  * Remove the uploaded image
174
  */
175
  public function qsm_remove_file_fd_question() {
176
- $file_url = isset( $_POST['file_url'] ) ? sanitize_text_field( wp_unslash( $_POST['file_url'] ) ) : '';
177
- $upload_dir = wp_upload_dir();
178
- $uploaded_path = $upload_dir['path'];
179
- if ( $file_url && stristr( $file_url, 'qsmfileupload_' ) && file_exists( $uploaded_path . '/' . $file_url ) ) {
180
- $attachment_url = $upload_dir['url'] . '/' . $file_url;
181
- $attachment_id = $this->qsm_get_attachment_id_from_url( $attachment_url );
182
- wp_delete_file( $uploaded_path . '/' . $file_url );
183
- wp_delete_attachment( $attachment_id );
184
- $json['type'] = 'success';
185
- $json['message'] = __( 'File removed successfully', 'quiz-master-next' );
186
- echo wp_json_encode( $json );
187
- exit;
188
  }
 
189
  $json['type'] = 'error';
190
  $json['message'] = __( 'File not removed', 'quiz-master-next' );
191
  echo wp_json_encode( $json );
@@ -209,7 +213,7 @@ class QMNQuizManager {
209
  $correct_answer = false;
210
  if ( $answer_array && false === $got_ans ) {
211
  foreach ( $answer_array as $key => $value ) {
212
- if ( $value[0] == $answer && 1 == $value[2] ) {
213
  $got_ans = true;
214
  $correct_answer = true;
215
  break;
@@ -390,6 +394,11 @@ class QMNQuizManager {
390
  'quiz_system' => $qmn_quiz_options->system,
391
  'user_ip' => $this->get_user_ip(),
392
  );
 
 
 
 
 
393
  $qpages = array();
394
  $qpages_arr = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'qpages', array() );
395
  if ( ! empty( $qpages_arr ) ) {
@@ -409,6 +418,7 @@ class QMNQuizManager {
409
  'skip_validation_time_expire' => $qmn_quiz_options->skip_validation_time_expire,
410
  'timer_limit_val' => $qmn_quiz_options->timer_limit,
411
  'disable_scroll_next_previous_click' => $qmn_quiz_options->disable_scroll_next_previous_click,
 
412
  'enable_result_after_timer_end' => isset( $qmn_quiz_options->enable_result_after_timer_end ) ? $qmn_quiz_options->enable_result_after_timer_end : '',
413
  'enable_quick_result_mc' => isset( $qmn_quiz_options->enable_quick_result_mc ) ? $qmn_quiz_options->enable_quick_result_mc : '',
414
  'end_quiz_if_wrong' => isset( $qmn_quiz_options->end_quiz_if_wrong ) ? $qmn_quiz_options->end_quiz_if_wrong : '',
@@ -432,10 +442,12 @@ class QMNQuizManager {
432
 
433
  $qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables, $atts );
434
 
435
- $return_display .= ob_get_clean();
436
- $return_display = apply_filters( 'qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables, $atts );
437
- $qmn_quiz_data[ $qmn_json_data['quiz_id'] ] = $qmn_filtered_json;
438
- wp_localize_script( 'qsm_quiz', 'qmn_quiz_data', $qmn_quiz_data );
 
 
439
  }
440
  return $return_display;
441
  }
@@ -584,14 +596,19 @@ class QMNQuizManager {
584
 
585
  // check If we should load a specific number of question
586
  if ( 0 != $quiz_options->question_per_category && $is_quiz_page ) {
587
- $categories = QSM_Questions::get_quiz_categories( $quiz_id );
588
- $category_ids = ( isset( $categories['list'] ) ? array_keys( $categories['list'] ) : array() );
 
589
  $categories_tree = ( isset( $categories['tree'] ) ? $categories['tree'] : array() );
 
590
  if ( ! empty( $category_ids ) ) {
591
- $term_ids = implode( ',', $category_ids );
592
- $term_ids = ( '' !== $quiz_options->randon_category ) ? $quiz_options->randon_category : $term_ids;
593
- $tq_ids = $wpdb->get_results( "SELECT `term_id`, `question_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `quiz_id`='{$quiz_id}' AND `term_id` IN ({$term_ids}) AND `taxonomy`='qsm_category'", ARRAY_A );
594
- $random = array();
 
 
 
595
  if ( ! empty( $tq_ids ) ) {
596
  $term_data = array();
597
  foreach ( $tq_ids as $key => $val ) {
@@ -1013,7 +1030,7 @@ class QMNQuizManager {
1013
  ?>
1014
  <span class="pages_count">
1015
  <?php
1016
- $text_c = $pages_count . __( ' out of ', 'quiz-master-next' ) . $total_pages_count;
1017
  echo apply_filters( 'qsm_total_pages_count', $text_c, $pages_count, $total_pages_count );
1018
  ?>
1019
  </span>
@@ -1080,6 +1097,7 @@ class QMNQuizManager {
1080
  ?>
1081
  <input type="hidden" name="qmn_question_list" value="<?php echo esc_attr( $question_list ); ?>" />
1082
  <?php
 
1083
  }
1084
 
1085
  /**
@@ -1217,7 +1235,7 @@ class QMNQuizManager {
1217
  ?>
1218
  <span class="pages_count" style="display: none;">
1219
  <?php
1220
- $text_c = $current_page_number . __( ' out of ', 'quiz-master-next' ) . $total_pagination;
1221
  echo apply_filters( 'qsm_total_pages_count', $text_c, $pages_count, $total_pages_count );
1222
  ?>
1223
  </span>
@@ -1273,25 +1291,29 @@ class QMNQuizManager {
1273
  $section_display = '';
1274
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1275
  $pagination_optoin = $qmn_quiz_options->pagination;
1276
- // Legacy Code.
1277
- if ( ! empty( $qmn_quiz_options->message_end_template ) ) {
1278
- $message_end = wpautop( htmlspecialchars_decode( $qmn_quiz_options->message_end_template, ENT_QUOTES ) );
1279
- $message_end = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_end, $qmn_array_for_variables );
1280
- $section_display .= "<span class='mlw_qmn_message_end'>$message_end</span>";
1281
- $section_display .= '<br /><br />';
1282
- }
1283
- if ( 1 == $qmn_quiz_options->contact_info_location ) {
1284
- $section_display .= QSM_Contact_Manager::display_fields( $qmn_quiz_options );
1285
- }
1286
 
1287
  do_action( 'mlw_qmn_end_quiz_section' );
1288
- $qsm_d_none = 0 == $qmn_quiz_options->randomness_order ? 'qsm-d-none' : '';
1289
- if ( ! empty( $section_display ) ) {
1290
  ?>
1291
  <br />
1292
  <div class="qsm-auto-page-row quiz_section quiz_end <?php echo esc_attr( $qsm_d_none ); ?>">
1293
  <?php
1294
- echo wp_kses_post( $section_display );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1295
  ?>
1296
  <input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value="<?php echo esc_attr( $qmn_quiz_options->submit_button_text ); ?>" />
1297
  </div>
@@ -1363,8 +1385,11 @@ class QMNQuizManager {
1363
  if ( ! $verified ) {
1364
  echo wp_json_encode(
1365
  array(
1366
- 'display' => htmlspecialchars_decode( 'ReCaptcha Validation failed' ),
1367
- 'redirect' => false,
 
 
 
1368
  )
1369
  );
1370
  exit;
@@ -1464,8 +1489,8 @@ class QMNQuizManager {
1464
  $qmn_array_for_variables = apply_filters( 'qsm_result_variables', $qmn_array_for_variables );
1465
 
1466
  if ( ! isset( $_POST['mlw_code_captcha'] ) || ( isset( $_POST['mlw_code_captcha'], $_POST['mlw_user_captcha'] ) && sanitize_text_field( wp_unslash( $_POST['mlw_user_captcha'] ) ) == sanitize_text_field( wp_unslash( $_POST['mlw_code_captcha'] ) ) ) ) {
1467
-
1468
- $qmn_array_for_variables = array_merge( $qmn_array_for_variables, $this->check_answers( $qmn_quiz_options, $qmn_array_for_variables ) );
1469
  $result_display = apply_filters( 'qmn_after_check_answers', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
1470
  $qmn_array_for_variables['comments'] = $this->check_comment_section( $qmn_quiz_options, $qmn_array_for_variables );
1471
  $result_display = apply_filters( 'qmn_after_check_comments', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
@@ -1742,11 +1767,8 @@ class QMNQuizManager {
1742
  }
1743
 
1744
  // Send question to our grading function
1745
- $results_array = apply_filters( 'qmn_results_array', $mlwQuizMasterNext->pluginHelper->display_review( $question['question_type_new'], $question['question_id'] ), $question );
1746
- if ( isset( $results_array['question_type'] ) && 'file_upload' === $results_array['question_type'] ) {
1747
- $results_array['user_text'] = '<a target="_blank" href="' . $results_array['user_text'] . '">' . __( 'Click here to view', 'quiz-master-next' ) . '</a>';
1748
- }
1749
-
1750
  // If question was graded correctly.
1751
  if ( ! isset( $results_array['null_review'] ) ) {
1752
  if ( in_array( intval( $question_type_new ), $result_question_types, true ) && ! in_array( intval( $question_id ), $hidden_questions, true ) ) {
@@ -1790,6 +1812,8 @@ class QMNQuizManager {
1790
  htmlspecialchars( $user_answer, ENT_QUOTES ),
1791
  htmlspecialchars( $correct_answer, ENT_QUOTES ),
1792
  $comment,
 
 
1793
  'correct' => $correct_status,
1794
  'id' => $question['question_id'],
1795
  'points' => $answer_points,
@@ -1828,9 +1852,9 @@ class QMNQuizManager {
1828
  $total_possible_points += $max_min_result['max_point'];
1829
  $minimum_possible_points += $max_min_result['min_point'];
1830
 
1831
- // Send question to our grading function.
1832
- $results_array = apply_filters( 'qmn_results_array', $mlwQuizMasterNext->pluginHelper->display_review( $question['question_type_new'], $question['question_id'] ), $question );
1833
-
1834
  // If question was graded correctly.
1835
  if ( ! isset( $results_array['null_review'] ) ) {
1836
  $points_earned += $results_array['points'];
@@ -1870,6 +1894,8 @@ class QMNQuizManager {
1870
  htmlspecialchars( $user_answer, ENT_QUOTES ),
1871
  htmlspecialchars( $correct_answer, ENT_QUOTES ),
1872
  $comment,
 
 
1873
  'correct' => $correct_status,
1874
  'id' => $question['question_id'],
1875
  'points' => $answer_points,
@@ -1898,9 +1924,10 @@ class QMNQuizManager {
1898
 
1899
  // Get random order
1900
  $qsm_random_que_ids = get_option( 'qsm_random_que_ids' );
 
1901
  if ( ! empty( $qsm_random_que_ids ) && is_array( $qsm_random_que_ids ) ) {
1902
  $qs_ids = array_column( $question_data, 'id' );
1903
- $has_diff = array_diff( $qs_ids, $qsm_random_que_ids );
1904
  // Check random option value has all the questions in previous order
1905
  if ( empty( $has_diff ) ) {
1906
  $new_question_data = array();
@@ -2401,45 +2428,6 @@ class QMNQuizManager {
2401
  include_once plugin_dir_path( __FILE__ ) . 'class-qmn-background-process.php';
2402
  $this->qsm_background_email = new QSM_Background_Request();
2403
  }
2404
-
2405
- /**
2406
- * Get attachment id from attachment url
2407
- *
2408
- * @since 7.1.2
2409
- *
2410
- * @global obj $wpdb
2411
- * @param url $attachment_url
2412
- * @return int
2413
- */
2414
- public function qsm_get_attachment_id_from_url( $attachment_url = '' ) {
2415
-
2416
- global $wpdb;
2417
- $attachment_id = false;
2418
-
2419
- // If there is no url, return.
2420
- if ( '' == $attachment_url ) {
2421
- return;
2422
- }
2423
-
2424
- // Get the upload directory paths
2425
- $upload_dir_paths = wp_upload_dir();
2426
-
2427
- // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
2428
- if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) {
2429
-
2430
- // If this is the URL of an auto-generated thumbnail, get the URL of the original image
2431
- $attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url );
2432
-
2433
- // Remove the upload path base directory from the attachment URL
2434
- $attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url );
2435
-
2436
- // Finally, run a custom database query to get the attachment ID from the modified attachment URL
2437
- $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url ) );
2438
-
2439
- }
2440
-
2441
- return $attachment_id;
2442
- }
2443
  }
2444
 
2445
  global $qmnQuizManager;
113
  $json = array();
114
  if ( ! isset( $_FILES['file'] ) ) {
115
  $json['type'] = 'error';
116
+ $json['message'] = __( 'File is not uploaded!', 'quiz-master-next' );
117
  echo wp_json_encode( $json );
118
  exit;
119
  }
149
  include_once ABSPATH . 'wp-admin/includes/image.php';
150
  $attach_data = wp_generate_attachment_metadata( $attach_id, $movefile['file'] );
151
  wp_update_attachment_metadata( $attach_id, $attach_data );
152
+ $json['type'] = 'success';
153
+ $json['media_id'] = $attach_id;
154
+ $json['message'] = __( 'File uploaded successfully', 'quiz-master-next' );
155
+ $json['file_url'] = $movefile['url'];
156
+ $json['file_path'] = basename( $movefile['url'] );
157
+ echo wp_json_encode( $json );
158
+ } else {
159
+ $json['type'] = 'error';
160
+ $json['message'] = __( 'Upload failed!', 'quiz-master-next' );
161
+ echo wp_json_encode( $json );
162
  }
 
 
 
 
 
163
  } else {
164
  $json['type'] = 'error';
165
  $json['message'] = $movefile['error'];
167
  }
168
  } else {
169
  $json['type'] = 'error';
170
+ $json['message'] = __( 'File type is not supported!', 'quiz-master-next' );
171
  echo wp_json_encode( $json );
172
  }
173
  exit;
178
  * Remove the uploaded image
179
  */
180
  public function qsm_remove_file_fd_question() {
181
+ $json = array();
182
+ $attachment_id = isset( $_POST['media_id'] ) ? intval( $_POST['media_id'] ) : '';
183
+ if ( ! empty( $attachment_id ) ) {
184
+ $delete = wp_delete_attachment( $attachment_id, true );
185
+ if ( $delete ) {
186
+ $json['type'] = 'success';
187
+ $json['message'] = __( 'File removed successfully', 'quiz-master-next' );
188
+ echo wp_json_encode( $json );
189
+ exit;
190
+ }
 
 
191
  }
192
+
193
  $json['type'] = 'error';
194
  $json['message'] = __( 'File not removed', 'quiz-master-next' );
195
  echo wp_json_encode( $json );
213
  $correct_answer = false;
214
  if ( $answer_array && false === $got_ans ) {
215
  foreach ( $answer_array as $key => $value ) {
216
+ if ( intval( $answer) === $key && 1 === intval( $value[2] ) ) {
217
  $got_ans = true;
218
  $correct_answer = true;
219
  break;
394
  'quiz_system' => $qmn_quiz_options->system,
395
  'user_ip' => $this->get_user_ip(),
396
  );
397
+ $return_display .= '<script>
398
+ if (window.qmn_quiz_data === undefined) {
399
+ window.qmn_quiz_data = new Object();
400
+ }
401
+ </script>';
402
  $qpages = array();
403
  $qpages_arr = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'qpages', array() );
404
  if ( ! empty( $qpages_arr ) ) {
418
  'skip_validation_time_expire' => $qmn_quiz_options->skip_validation_time_expire,
419
  'timer_limit_val' => $qmn_quiz_options->timer_limit,
420
  'disable_scroll_next_previous_click' => $qmn_quiz_options->disable_scroll_next_previous_click,
421
+ 'disable_first_page' => $qmn_quiz_options->disable_first_page,
422
  'enable_result_after_timer_end' => isset( $qmn_quiz_options->enable_result_after_timer_end ) ? $qmn_quiz_options->enable_result_after_timer_end : '',
423
  'enable_quick_result_mc' => isset( $qmn_quiz_options->enable_quick_result_mc ) ? $qmn_quiz_options->enable_quick_result_mc : '',
424
  'end_quiz_if_wrong' => isset( $qmn_quiz_options->end_quiz_if_wrong ) ? $qmn_quiz_options->end_quiz_if_wrong : '',
442
 
443
  $qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables, $atts );
444
 
445
+ $return_display .= '<script>window.qmn_quiz_data["' . $qmn_json_data['quiz_id'] . '"] = ' . wp_json_encode( $qmn_filtered_json ) . '
446
+ </script>';
447
+
448
+ $return_display .= ob_get_clean();
449
+ $return_display = apply_filters( 'qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables, $atts );
450
+
451
  }
452
  return $return_display;
453
  }
596
 
597
  // check If we should load a specific number of question
598
  if ( 0 != $quiz_options->question_per_category && $is_quiz_page ) {
599
+ $categories = QSM_Questions::get_quiz_categories( $quiz_id );
600
+ $category_ids = ( isset( $categories['list'] ) ? array_keys( $categories['list'] ) : array() );
601
+
602
  $categories_tree = ( isset( $categories['tree'] ) ? $categories['tree'] : array() );
603
+
604
  if ( ! empty( $category_ids ) ) {
605
+ $term_ids = implode( ',', $category_ids );
606
+ $question_id = implode( ',', $question_ids );
607
+ $term_ids = ( '' !== $quiz_options->randon_category ) ? $quiz_options->randon_category : $term_ids;
608
+
609
+ $tq_ids = $wpdb->get_results( "SELECT `term_id`, `question_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id` IN ({$question_id}) AND `term_id` IN ({$term_ids}) AND `taxonomy`='qsm_category'", ARRAY_A );
610
+
611
+ $random = array();
612
  if ( ! empty( $tq_ids ) ) {
613
  $term_data = array();
614
  foreach ( $tq_ids as $key => $val ) {
1030
  ?>
1031
  <span class="pages_count">
1032
  <?php
1033
+ $text_c = $pages_count . esc_html__( ' out of ', 'quiz-master-next' ) . $total_pages_count;
1034
  echo apply_filters( 'qsm_total_pages_count', $text_c, $pages_count, $total_pages_count );
1035
  ?>
1036
  </span>
1097
  ?>
1098
  <input type="hidden" name="qmn_question_list" value="<?php echo esc_attr( $question_list ); ?>" />
1099
  <?php
1100
+
1101
  }
1102
 
1103
  /**
1235
  ?>
1236
  <span class="pages_count" style="display: none;">
1237
  <?php
1238
+ $text_c = $current_page_number . esc_html__( ' out of ', 'quiz-master-next' ) . $total_pagination;
1239
  echo apply_filters( 'qsm_total_pages_count', $text_c, $pages_count, $total_pages_count );
1240
  ?>
1241
  </span>
1291
  $section_display = '';
1292
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1293
  $pagination_optoin = $qmn_quiz_options->pagination;
 
 
 
 
 
 
 
 
 
 
1294
 
1295
  do_action( 'mlw_qmn_end_quiz_section' );
1296
+ $qsm_d_none = 0 === intval( $qmn_quiz_options->randomness_order ) ? 'qsm-d-none' : '';
1297
+ if ( ! empty( $qmn_quiz_options->message_end_template ) || ( 1 === intval( $qmn_quiz_options->contact_info_location ) && ! empty( QSM_Contact_Manager::display_fields( $qmn_quiz_options ) ) ) ) {
1298
  ?>
1299
  <br />
1300
  <div class="qsm-auto-page-row quiz_section quiz_end <?php echo esc_attr( $qsm_d_none ); ?>">
1301
  <?php
1302
+ // Legacy Code.
1303
+ if ( ! empty( $qmn_quiz_options->message_end_template ) ) {
1304
+ ?>
1305
+ <span class='mlw_qmn_message_end'>
1306
+ <?php
1307
+ $message_end = wpautop( htmlspecialchars_decode( $qmn_quiz_options->message_end_template, ENT_QUOTES ) );
1308
+ echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_end, $qmn_array_for_variables );
1309
+ ?>
1310
+ </span>
1311
+ <br /><br />
1312
+ <?php
1313
+ }
1314
+ if ( 1 === intval( $qmn_quiz_options->contact_info_location ) ) {
1315
+ echo QSM_Contact_Manager::display_fields( $qmn_quiz_options );
1316
+ }
1317
  ?>
1318
  <input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value="<?php echo esc_attr( $qmn_quiz_options->submit_button_text ); ?>" />
1319
  </div>
1385
  if ( ! $verified ) {
1386
  echo wp_json_encode(
1387
  array(
1388
+ 'display' => htmlspecialchars_decode( 'ReCaptcha Validation failed' ),
1389
+ 'redirect' => false,
1390
+ 'result_status' => array(
1391
+ 'save_response' => false,
1392
+ ),
1393
  )
1394
  );
1395
  exit;
1489
  $qmn_array_for_variables = apply_filters( 'qsm_result_variables', $qmn_array_for_variables );
1490
 
1491
  if ( ! isset( $_POST['mlw_code_captcha'] ) || ( isset( $_POST['mlw_code_captcha'], $_POST['mlw_user_captcha'] ) && sanitize_text_field( wp_unslash( $_POST['mlw_user_captcha'] ) ) == sanitize_text_field( wp_unslash( $_POST['mlw_code_captcha'] ) ) ) ) {
1492
+ $qsm_check_answers_return = $this->check_answers( $qmn_quiz_options, $qmn_array_for_variables );
1493
+ $qmn_array_for_variables = array_merge( $qmn_array_for_variables, $qsm_check_answers_return );
1494
  $result_display = apply_filters( 'qmn_after_check_answers', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
1495
  $qmn_array_for_variables['comments'] = $this->check_comment_section( $qmn_quiz_options, $qmn_array_for_variables );
1496
  $result_display = apply_filters( 'qmn_after_check_comments', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
1767
  }
1768
 
1769
  // Send question to our grading function
1770
+ $results_array = $mlwQuizMasterNext->pluginHelper->display_review( $question['question_type_new'], $question['question_id'] );
1771
+ $results_array = apply_filters( 'qmn_results_array', $results_array, $question );
 
 
 
1772
  // If question was graded correctly.
1773
  if ( ! isset( $results_array['null_review'] ) ) {
1774
  if ( in_array( intval( $question_type_new ), $result_question_types, true ) && ! in_array( intval( $question_id ), $hidden_questions, true ) ) {
1812
  htmlspecialchars( $user_answer, ENT_QUOTES ),
1813
  htmlspecialchars( $correct_answer, ENT_QUOTES ),
1814
  $comment,
1815
+ 'user_answer' => $results_array['user_answer'],
1816
+ 'correct_answer' => $results_array['correct_answer'],
1817
  'correct' => $correct_status,
1818
  'id' => $question['question_id'],
1819
  'points' => $answer_points,
1852
  $total_possible_points += $max_min_result['max_point'];
1853
  $minimum_possible_points += $max_min_result['min_point'];
1854
 
1855
+ // Send question to our grading function
1856
+ $results_array = $mlwQuizMasterNext->pluginHelper->display_review( $question['question_type_new'], $question['question_id'] );
1857
+ $results_array = apply_filters( 'qmn_results_array', $results_array, $question );
1858
  // If question was graded correctly.
1859
  if ( ! isset( $results_array['null_review'] ) ) {
1860
  $points_earned += $results_array['points'];
1894
  htmlspecialchars( $user_answer, ENT_QUOTES ),
1895
  htmlspecialchars( $correct_answer, ENT_QUOTES ),
1896
  $comment,
1897
+ 'user_answer' => $results_array['user_answer'],
1898
+ 'correct_answer' => $results_array['correct_answer'],
1899
  'correct' => $correct_status,
1900
  'id' => $question['question_id'],
1901
  'points' => $answer_points,
1924
 
1925
  // Get random order
1926
  $qsm_random_que_ids = get_option( 'qsm_random_que_ids' );
1927
+
1928
  if ( ! empty( $qsm_random_que_ids ) && is_array( $qsm_random_que_ids ) ) {
1929
  $qs_ids = array_column( $question_data, 'id' );
1930
+ $has_diff = array_diff( $qsm_random_que_ids, $qs_ids );
1931
  // Check random option value has all the questions in previous order
1932
  if ( empty( $has_diff ) ) {
1933
  $new_question_data = array();
2428
  include_once plugin_dir_path( __FILE__ ) . 'class-qmn-background-process.php';
2429
  $this->qsm_background_email = new QSM_Background_Request();
2430
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2431
  }
2432
 
2433
  global $qmnQuizManager;
php/classes/class-qsm-emails.php CHANGED
@@ -170,28 +170,10 @@ class QSM_Emails {
170
  // Prepares our subject.
171
  $subject = apply_filters( 'mlw_qmn_template_variable_results_page', $subject, $response_data );
172
  // Prepares our content.
173
- $incorrect_answer = "<span style='color:red;display:block;margin-bottom:5px;'>&#x2715;";
174
- $correct_answer = "<span style='color:green;display:block;margin-bottom:5px;'>&#10003;";
175
- $simple_answer = "<span style='color:#808080;display:block;margin-bottom:5px;'>&#8226;";
176
  $content = htmlspecialchars_decode( $content, ENT_QUOTES );
177
  $response_data['email_template_array'] = true;
178
  $content = apply_filters( 'mlw_qmn_template_variable_results_page', $content, $response_data );
179
  $content = apply_filters( 'qmn_email_template_variable_results', $content, $response_data );
180
- $content = str_replace( '<br/>', '<br>', $content );
181
- $content = str_replace( '<br />', '<br>', $content );
182
- $content = str_replace( "<span class='qmn_user_incorrect_answer'>", "<span style='color:red'>&#x2715; ", $content );
183
- $content = str_replace( "<span class='qmn_user_correct_answer'>", "<span style='color:green'>&#10003; ", $content );
184
- $content = str_replace( '<span class="qsm-text-wrong-option qmn_image_option">', "$incorrect_answer ", $content );
185
- $content = str_replace( '<span class="qsm-text-correct-option qmn_image_option">', "$correct_answer ", $content );
186
- $content = str_replace( '<span class="qsm-text-correct-option qsm-text-user-correct-answer qmn_image_option">', "$correct_answer ", $content );
187
- $content = str_replace( '<span class="qsm-text-simple-option qmn_image_option">', "$simple_answer ", $content );
188
- $content = str_replace( '<span class="qsm-text-correct-option qsm-text-user-correct-answer ">', "$correct_answer ", $content );
189
- $content = str_replace( '<span class="qsm-text-simple-option ">', "$simple_answer ", $content );
190
- $content = str_replace( '<span class="qsm-text-wrong-option ">', "$incorrect_answer ", $content );
191
- $content = str_replace( '<span class="qsm-text-correct-option ">', "$correct_answer ", $content );
192
- $content = str_replace( '<span class="qmn_user_incorrect_answer">', "$incorrect_answer ", $content );
193
- $content = str_replace( '<span class="qmn_user_correct_answer">', "$correct_answer ", $content );
194
- $content = str_replace( "class='qmn_question_answer", "style='margin-bottom:30px' class='", $content );
195
  // convert css classes to inline.
196
  $content = $mlwQuizMasterNext->pluginHelper->qsm_results_css_inliner( $content );
197
  $content = html_entity_decode( $content );
170
  // Prepares our subject.
171
  $subject = apply_filters( 'mlw_qmn_template_variable_results_page', $subject, $response_data );
172
  // Prepares our content.
 
 
 
173
  $content = htmlspecialchars_decode( $content, ENT_QUOTES );
174
  $response_data['email_template_array'] = true;
175
  $content = apply_filters( 'mlw_qmn_template_variable_results_page', $content, $response_data );
176
  $content = apply_filters( 'qmn_email_template_variable_results', $content, $response_data );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  // convert css classes to inline.
178
  $content = $mlwQuizMasterNext->pluginHelper->qsm_results_css_inliner( $content );
179
  $content = html_entity_decode( $content );
php/classes/class-qsm-install.php CHANGED
@@ -689,6 +689,25 @@ class QSM_Install {
689
  );
690
  $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' );
691
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  // Setting for animation
693
  $field_array = array(
694
  'id' => 'quiz_animation',
@@ -1282,7 +1301,7 @@ class QSM_Install {
1282
  quiz_views INT NOT NULL,
1283
  quiz_taken INT NOT NULL,
1284
  deleted INT NOT NULL,
1285
- quiz_author_id INT NOT NULL,
1286
  PRIMARY KEY (quiz_id)
1287
  ) $charset_collate;";
1288
 
@@ -1697,6 +1716,12 @@ class QSM_Install {
1697
  $results = $wpdb->query( $update_sql );
1698
  }
1699
 
 
 
 
 
 
 
1700
  // Update 3.7.1
1701
  if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'scheduled_timeframe'" ) != 'scheduled_timeframe' ) {
1702
  $sql = 'ALTER TABLE ' . $table_name . ' ADD scheduled_timeframe TEXT NOT NULL AFTER limit_total_entries_text';
689
  );
690
  $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' );
691
 
692
+ // Setting for display first page
693
+ $field_array = array(
694
+ 'id' => 'disable_first_page',
695
+ 'label' => __( 'Disable first page on quiz', 'quiz-master-next' ),
696
+ 'type' => 'radio',
697
+ 'options' => array(
698
+ array(
699
+ 'label' => __( 'Yes', 'quiz-master-next' ),
700
+ 'value' => 1,
701
+ ),
702
+ array(
703
+ 'label' => __( 'No', 'quiz-master-next' ),
704
+ 'value' => 0,
705
+ ),
706
+ ),
707
+ 'default' => 0,
708
+ );
709
+ $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' );
710
+
711
  // Setting for animation
712
  $field_array = array(
713
  'id' => 'quiz_animation',
1301
  quiz_views INT NOT NULL,
1302
  quiz_taken INT NOT NULL,
1303
  deleted INT NOT NULL,
1304
+ quiz_author_id INT NOT NULL,
1305
  PRIMARY KEY (quiz_id)
1306
  ) $charset_collate;";
1307
 
1716
  $results = $wpdb->query( $update_sql );
1717
  }
1718
 
1719
+ // Update 7.3.8
1720
+ if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'quiz_author_id'" ) != 'quiz_author_id' ) {
1721
+ $sql = 'ALTER TABLE ' . $table_name . ' ADD quiz_author_id TEXT NOT NULL AFTER deleted';
1722
+ $results = $wpdb->query( $sql );
1723
+ }
1724
+
1725
  // Update 3.7.1
1726
  if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'scheduled_timeframe'" ) != 'scheduled_timeframe' ) {
1727
  $sql = 'ALTER TABLE ' . $table_name . ' ADD scheduled_timeframe TEXT NOT NULL AFTER limit_total_entries_text';
php/classes/class-qsm-questions.php CHANGED
@@ -51,6 +51,14 @@ class QSM_Questions {
51
  return array();
52
  }
53
 
 
 
 
 
 
 
 
 
54
  /**
55
  * Loads questions for a quiz using the new page system
56
  *
@@ -272,8 +280,8 @@ class QSM_Questions {
272
  );
273
  $settings = wp_parse_args( $settings, $defaults );
274
 
275
- $answers = self::sanitize_answers( $answers, $settings );
276
- foreach ( $answers as $key => $answer ) {
277
  $answers_array = array(
278
  htmlspecialchars( $answer[0], ENT_QUOTES ),
279
  floatval( $answer[1] ),
@@ -282,8 +290,9 @@ class QSM_Questions {
282
  if ( isset( $answer[3] ) ) {
283
  array_push( $answers_array, htmlspecialchars( $answer[3], ENT_QUOTES ) );
284
  }
285
- $answers[ $key ] = $answers_array;
286
  }
 
287
 
288
  $question_name = htmlspecialchars( wp_kses_post( $data['name'] ), ENT_QUOTES );
289
  $trim_question_description = apply_filters( 'qsm_trim_question_description', true );
51
  return array();
52
  }
53
 
54
+ /**
55
+ *
56
+ */
57
+ public static function load_question_data( $question_id, $question_data ) {
58
+ global $wpdb;
59
+ return $wpdb->get_var("SELECT {$question_data} FROM {$wpdb->prefix}mlw_questions WHERE question_id = {$question_id} LIMIT 1");
60
+ }
61
+
62
  /**
63
  * Loads questions for a quiz using the new page system
64
  *
280
  );
281
  $settings = wp_parse_args( $settings, $defaults );
282
 
283
+ $sanitize_answers = self::sanitize_answers( $answers, $settings );
284
+ foreach ( $sanitize_answers as $key => $answer ) {
285
  $answers_array = array(
286
  htmlspecialchars( $answer[0], ENT_QUOTES ),
287
  floatval( $answer[1] ),
290
  if ( isset( $answer[3] ) ) {
291
  array_push( $answers_array, htmlspecialchars( $answer[3], ENT_QUOTES ) );
292
  }
293
+ $sanitize_answers[ $key ] = $answers_array;
294
  }
295
+ $answers = apply_filters( 'qsm_answers_before_save', $sanitize_answers, $answers, $data );
296
 
297
  $question_name = htmlspecialchars( wp_kses_post( $data['name'] ), ENT_QUOTES );
298
  $trim_question_description = apply_filters( 'qsm_trim_question_description', true );
php/classes/class-qsm-settings.php CHANGED
@@ -212,6 +212,7 @@ class QSM_Quiz_Settings
212
  $setDefaultvalue['enable_deselect_option'] = $getdefaultvalue['enable_deselect_option'];
213
  $setDefaultvalue['disable_description_on_result'] = $getdefaultvalue['disable_description_on_result'];
214
  $setDefaultvalue['disable_scroll_next_previous_click'] = $getdefaultvalue['disable_scroll_next_previous_click'];
 
215
  $setDefaultvalue['quiz_animation'] = $getdefaultvalue['quiz_animation'];
216
  $setDefaultvalue['result_page_fb_image'] = $getdefaultvalue['result_page_fb_image'];
217
  $setDefaultvalue['randomness_order'] = $getdefaultvalue['randomness_order'];
212
  $setDefaultvalue['enable_deselect_option'] = $getdefaultvalue['enable_deselect_option'];
213
  $setDefaultvalue['disable_description_on_result'] = $getdefaultvalue['disable_description_on_result'];
214
  $setDefaultvalue['disable_scroll_next_previous_click'] = $getdefaultvalue['disable_scroll_next_previous_click'];
215
+ $setDefaultvalue['disable_first_page'] = $getdefaultvalue['disable_first_page'];
216
  $setDefaultvalue['quiz_animation'] = $getdefaultvalue['quiz_animation'];
217
  $setDefaultvalue['result_page_fb_image'] = $getdefaultvalue['result_page_fb_image'];
218
  $setDefaultvalue['randomness_order'] = $getdefaultvalue['randomness_order'];
php/classes/question-types/class-question-review-choice.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class QSM_Question_Review_Choice extends QSM_Question_Review {
7
+
8
+ function __construct( $question_id = 0, $question_title_old = '', $answer_array = array() ) {
9
+ parent::__construct( $question_id, $question_title_old, $answer_array );
10
+ }
11
+
12
+ public function set_user_answer() {
13
+ if ( isset( $_POST[ 'question' . $this->question_id ] ) ) {
14
+ $user_response = isset( $_POST[ 'question' . $this->question_id ] ) ? wp_unslash( $_POST[ 'question' . $this->question_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
15
+ if ( is_array( $user_response ) ) {
16
+ foreach ( $user_response as $user_response_single ) {
17
+ $user_answer_key = intval( $this->sanitize_answer_from_post( $user_response_single ) );
18
+ $user_answer_value = $this->sanitize_answer_from_db( $this->answer_array[ $user_answer_key ][0], $this->input_field );
19
+ $this->user_answer[ $user_answer_key ] = $user_answer_value;
20
+ }
21
+ } else {
22
+ $user_answer_key = intval( $this->sanitize_answer_from_post( $user_response ) );
23
+ $user_answer_value = $this->sanitize_answer_from_db( $this->answer_array[ $user_answer_key ][0], $this->input_field );
24
+ $this->user_answer[ $user_answer_key ] = $user_answer_value;
25
+ }
26
+ }
27
+ }
28
+
29
+ public function set_answer_status() {
30
+ foreach ( $this->user_answer as $user_answer_key => $user_answer_value ) {
31
+ if ( in_array( $user_answer_key, array_keys( $this->correct_answer ), true ) ) {
32
+ $this->answer_status = 'correct';
33
+ $this->points += $this->answer_array[ $user_answer_key ][2];
34
+ }
35
+ }
36
+ }
37
+ }
php/classes/question-types/class-question-review-file-upload.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class QSM_Question_Review_File_Upload extends QSM_Question_Review {
7
+ function __construct( $question_id = 0, $question_title_old = '', $answer_array = array() ) {
8
+ parent::__construct( $question_id, $question_title_old, $answer_array );
9
+ }
10
+
11
+ public function set_user_answer() {
12
+ if ( isset( $_POST[ 'question' . $this->question_id ] ) ) {
13
+ $user_answer_key = 'url';
14
+ $user_answer_value = $this->sanitize_answer_from_post( wp_unslash( $_POST[ 'question' . $this->question_id ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
15
+ $this->user_answer[ $user_answer_key ] = $user_answer_value;
16
+ }
17
+ }
18
+
19
+ public function set_answer_status() {
20
+ $this->answer_status = 'correct';
21
+ }
22
+ }
php/classes/question-types/class-question-review-fill-in-blanks.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class QSM_Question_Review_Fill_In_Blanks extends QSM_Question_Review {
7
+
8
+ function __construct( $question_id = 0, $question_title_old = '', $answer_array = array() ) {
9
+ parent::__construct( $question_id, $question_title_old, $answer_array );
10
+ }
11
+ public function get_question_text() {
12
+ if ( strpos( $this->question_description, '%BLANK%' ) !== false || strpos( $this->question_description, '%blank%' ) !== false ) {
13
+ return str_replace( array( '%BLANK%', '%blank%' ), array( '__________', '__________' ), do_shortcode( htmlspecialchars_decode( $this->question_description, ENT_QUOTES ) ) );
14
+ } else {
15
+ return false;
16
+ }
17
+ }
18
+
19
+ public function set_user_answer() {
20
+ if ( isset( $_POST[ 'question' . $this->question_id ] ) ) {
21
+ $user_response = wp_unslash( $_POST[ 'question' . $this->question_id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
22
+ foreach ( $user_response as $user_answer_key => $user_answer_value ) {
23
+ $user_answer_value = $this->sanitize_answer_from_post( $user_answer_value, 'text' );
24
+ $user_answer_value = $this->decode_response_from_text_field( $user_answer_value );
25
+ $this->user_answer[ $user_answer_key ] = $user_answer_value;
26
+ }
27
+ }
28
+ return $this->user_answer;
29
+ }
30
+
31
+ public function set_correct_answer() {
32
+ foreach ( $this->answer_array as $answer_key => $answer_value ) {
33
+ $this->correct_answer[ $answer_key ] = $this->sanitize_answer_from_db( $answer_value[0], $this->input_field );
34
+ }
35
+ }
36
+
37
+ public function set_answer_status() {
38
+ global $mlwQuizMasterNext;
39
+ $match_answer = $mlwQuizMasterNext->pluginHelper->get_question_setting( $this->question_id, 'matchAnswer' );
40
+ if ( 'sequence' === $match_answer ) {
41
+ $this->process_sequentially();
42
+ } else {
43
+ $this->process_randomly();
44
+ }
45
+ }
46
+
47
+ private function process_randomly() {
48
+ $total_user_answers = sizeof( $this->user_answer );
49
+ $total_correct_answer = sizeof( $this->correct_answer );
50
+ if ( $total_user_answers <= $total_correct_answer ) {
51
+ foreach ( $this->user_answer as $user_answer ) {
52
+ $answer_key = array_search( $this->prepare_for_string_matching( $user_answer ), array_map( array( $this, 'prepare_for_string_matching' ), $this->correct_answer ), true );
53
+ if ( false !== $answer_key ) {
54
+ $this->answer_status = 'correct';
55
+ $this->points += $this->answer_array[ $answer_key ][2];
56
+ } else {
57
+ $this->answer_status = 'incorrect';
58
+ }
59
+ }
60
+ } else {
61
+ foreach ( $this->correct_answer as $correct_answer ) {
62
+ $answer_key = array_search( $this->prepare_for_string_matching( $correct_answer ), array_map( array( $this, 'prepare_for_string_matching' ), $this->user_answer ), true );
63
+ if ( false !== $answer_key ) {
64
+ $this->answer_status = 'correct';
65
+ $this->points += $this->answer_array[ $answer_key ][2];
66
+ } else {
67
+ $this->answer_status = 'incorrect';
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ private function process_sequentially() {
74
+ $total_user_answers = sizeof( $this->user_answer );
75
+ $total_correct_answer = sizeof( $this->correct_answer );
76
+ if ( $total_user_answers <= $total_correct_answer ) {
77
+ foreach ( $this->user_answer as $user_answer_key => $user_answer ) {
78
+ if ( $this->prepare_for_string_matching( $user_answer ) === $this->prepare_for_string_matching( $this->correct_answer[ $user_answer_key ] ) ) {
79
+ $this->answer_status = 'correct';
80
+ $this->points += $this->answer_array[ $user_answer_key ][2];
81
+ } else {
82
+ $this->answer_status = 'incorrect';
83
+ }
84
+ }
85
+ } else {
86
+ foreach ( $this->correct_answer as $correct_answer_key => $correct_answer ) {
87
+ if ( $this->prepare_for_string_matching( $correct_answer ) === $this->prepare_for_string_matching( $this->user_answer[ $correct_answer_key ] ) ) {
88
+ $this->answer_status = 'correct';
89
+ $this->points += $this->answer_array[ $correct_answer_key ][2];
90
+ } else {
91
+ $this->answer_status = 'incorrect';
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
php/classes/question-types/class-question-review-text.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class QSM_Question_Review_Text extends QSM_Question_Review {
7
+
8
+ function __construct( $question_id = 0, $question_title_old = '', $answer_array = array() ) {
9
+ parent::__construct( $question_id, $question_title_old, $answer_array );
10
+ }
11
+
12
+ public function set_user_answer() {
13
+ if ( isset( $_POST[ 'question' . $this->question_id ] ) ) {
14
+ $user_answer_key = 'input';
15
+ $user_answer_value = $this->sanitize_answer_from_post( wp_unslash( $_POST[ 'question' . $this->question_id ], 'text_area' ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
16
+ $user_answer_value = $this->decode_response_from_text_field( $user_answer_value );
17
+ $this->user_answer[ $user_answer_key ] = $user_answer_value;
18
+ }
19
+ }
20
+
21
+ public function set_answer_status() {
22
+ $user_answer_value = $this->user_answer['input'];
23
+ $answer_key = array_search( $this->prepare_for_string_matching( $user_answer_value ), array_map( array( $this, 'prepare_for_string_matching' ), $this->correct_answer ), true );
24
+ if ( false !== $answer_key ) {
25
+ $this->answer_status = 'correct';
26
+ $this->points += $this->answer_array[ $answer_key ][2];
27
+ }
28
+ }
29
+ }
php/classes/question-types/class-question-review.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ abstract class QSM_Question_Review {
7
+ public $question_id = 0;
8
+ public $answer_array = array();
9
+ public $user_answer = array();
10
+ public $correct_answer = array();
11
+ public $answer_status = 'incorrect';
12
+ public $points = 0;
13
+ public $question_description = '';
14
+ public $input_field = '';
15
+
16
+ function __construct( $question_id = 0, $question_description = '', $answer_array = array() ) {
17
+ global $mlwQuizMasterNext;
18
+ $this->question_id = $question_id;
19
+ $this->answer_array = $answer_array;
20
+ $this->question_description = $question_description;
21
+ $this->question_type = QSM_Questions::load_question_data( $this->question_id, 'question_type_new' );
22
+ $this->input_field = $mlwQuizMasterNext->pluginHelper->question_types[ $this->question_type ]['input_field'];
23
+ $this->set_user_answer();
24
+ $this->set_correct_answer();
25
+ $this->set_answer_status();
26
+ }
27
+
28
+ public function sanitize_answer_from_post( $data, $type = 'text' ) {
29
+ if ( 'text_area' === $type ) {
30
+ return sanitize_textarea_field( wp_unslash( $data ) );
31
+ } else {
32
+ return sanitize_text_field( wp_unslash( $data ) );
33
+ }
34
+ }
35
+
36
+ public function sanitize_answer_from_db( $data, $type = 'text' ) {
37
+ if ( 'text_area' === $type ) {
38
+ return trim( stripslashes( htmlspecialchars_decode( sanitize_textarea_field( $data ), ENT_QUOTES ) ) );
39
+ } else {
40
+ return trim( stripslashes( htmlspecialchars_decode( sanitize_text_field( $data ), ENT_QUOTES ) ) );
41
+ }
42
+ }
43
+
44
+ public function decode_response_from_text_field( $data ) {
45
+ return trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', htmlspecialchars_decode( $data, ENT_QUOTES ) ) ) );
46
+ }
47
+
48
+
49
+ public function prepare_for_string_matching( $data ) {
50
+ return mb_strtoupper( str_replace( ' ', '', preg_replace( '/\s\s+/', '', $data ) ) );
51
+ }
52
+
53
+ abstract public function set_user_answer();
54
+
55
+ public function set_correct_answer() {
56
+ foreach ( $this->answer_array as $answer_key => $answer_value ) {
57
+ if ( 1 === intval( $answer_value[2] ) ) {
58
+ $this->correct_answer[ $answer_key ] = $this->sanitize_answer_from_db( $answer_value[0], $this->input_field );
59
+ }
60
+ }
61
+ }
62
+
63
+ abstract public function set_answer_status();
64
+
65
+ public function get_user_answer() {
66
+ return $this->user_answer;
67
+ }
68
+ public function get_correct_answer() {
69
+ return $this->correct_answer;
70
+ }
71
+ public function get_answer_status() {
72
+ return $this->answer_status;
73
+ }
74
+ public function get_points() {
75
+ return $this->points;
76
+ }
77
+ }
php/question-types.php CHANGED
@@ -1,10 +1,64 @@
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
  }
5
-
 
6
  add_action( 'plugins_loaded', 'qmn_question_type_multiple_choice' );
7
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  /**
9
  * Registers the multiple choice type
10
  *
@@ -12,11 +66,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_multiple_choice' );
12
  * @since 4.4.0
13
  */
14
  function qmn_question_type_multiple_choice() {
15
- global $mlwQuizMasterNext;
16
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Vertical Multiple Choice', 'quiz-master-next' ), 'qmn_multiple_choice_display', true, 'qmn_multiple_choice_review', null, null, 0 );
 
 
17
  }
18
-
19
- add_action( 'plugins_loaded', 'qmn_question_type_file_upload' );
20
  /**
21
  * Registers the file upload type
22
  *
@@ -24,225 +78,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_file_upload' );
24
  * @since 6.3.7
25
  */
26
  function qmn_question_type_file_upload() {
27
- global $mlwQuizMasterNext;
28
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'File Upload', 'quiz-master-next' ), 'qmn_file_upload_display', true, 'qmn_file_upload_review', null, null, 11 );
29
- }
30
-
31
- /**
32
- * This function shows the content of the file upload
33
- *
34
- * @param $id The ID of the multiple choice question
35
- * @param $question The question that is being edited.
36
- * @param @answers The array that contains the answers to the question.
37
- *
38
- * @since 6.3.7
39
- */
40
- function qmn_file_upload_display( $id, $question, $answers ) {
41
- global $mlwQuizMasterNext;
42
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
43
- if ( 0 == $required ) {
44
- $mlw_require_class = 'mlwRequiredFileUpload';
45
- } else {
46
- $mlw_require_class = '';
47
- }
48
- // $question_title = apply_filters('the_content', $question);
49
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
50
- qsm_question_title_func( $question, '', $new_question_title, $id );
51
- ?> <div></div><input type="file" class="mlw_answer_file_upload <?php echo esc_attr( $mlw_require_class ); ?>"/>
52
- <div style="display: none;" class="loading-uploaded-file"><img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( get_site_url() . '/wp-includes/images/spinner-2x.gif' ); ?>"></div>
53
- <div style="display: none;" class="remove-uploaded-file"><span class="dashicons dashicons-trash"></span></div>
54
- <input class="mlw_file_upload_hidden_value" type="hidden" name="question<?php echo esc_attr( $id ); ?>" value="" />
55
- <span style="display: none;" class='mlw-file-upload-error-msg'></span>
56
- <input class="mlw_file_upload_hidden_path" type="hidden" value="" />
57
- <?php
58
- echo apply_filters( 'qmn_file_upload_display_front', '', $id, $question, $answers );
59
- }
60
-
61
- /**
62
- * This function determines how the file upload will work.
63
- *
64
- * @params $id The ID of the multiple choice question
65
- * @params $question The question that is being edited.
66
- * @params @answers The array that contains the answers to the question.
67
- * @return $return_array Returns the graded question to the results page
68
- * @since 5.3.7
69
- */
70
- function qmn_file_upload_review( $id, $question, $answers ) {
71
- $return_array = array(
72
- 'points' => 0,
73
- 'correct' => 'incorrect',
74
- 'user_text' => '',
75
- 'correct_text' => '',
76
- 'question_type' => 'file_upload',
77
- );
78
- if ( isset( $_POST[ 'question' . $id ] ) ) {
79
- $decode_user_answer = sanitize_text_field( wp_unslash( $_POST[ 'question' . $id ] ) );
80
- $mlw_user_answer = trim( $decode_user_answer );
81
- } else {
82
- $mlw_user_answer = ' ';
83
- }
84
- $return_array['user_text'] = $mlw_user_answer;
85
- foreach ( $answers as $answer ) {
86
- $decode_correct_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
87
- $return_array['correct_text'] = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_correct_text ) ) );
88
- if ( mb_strtoupper( $return_array['user_text'] ) == mb_strtoupper( $return_array['correct_text'] ) ) {
89
- $return_array['correct'] = 'correct';
90
- $return_array['points'] = $answer[1];
91
- break;
92
- }
93
- }
94
- /**
95
- * Hook to filter answers array
96
- */
97
- return apply_filters( 'qmn_file_upload_review', $return_array, $answers );
98
- }
99
-
100
- /**
101
- * This function shows the content of the multiple choice question.
102
- *
103
- * @params $id The ID of the multiple choice question
104
- * @params $question The question that is being edited.
105
- * @params @answers The array that contains the answers to the question.
106
- *
107
- * @since 4.4.0
108
- */
109
- function qmn_multiple_choice_display( $id, $question, $answers ) {
110
- global $mlwQuizMasterNext;
111
- $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
112
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
113
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
114
- if ( 0 == $required ) {
115
- $mlw_require_class = 'mlwRequiredRadio';
116
- } else {
117
- $mlw_require_class = '';
118
- }
119
- // $question_title = apply_filters('the_content', $question);
120
- qsm_question_title_func( $question, 'multiple_choice', $new_question_title, $id );
121
- ?>
122
- <div class='qmn_radio_answers <?php echo esc_attr( $mlw_require_class ); ?>'>
123
- <?php
124
- if ( is_array( $answers ) ) {
125
- $mlw_answer_total = 0;
126
- foreach ( $answers as $answer_index => $answer ) {
127
- $mlw_answer_total++;
128
- if ( '' !== $answer[0] ) {
129
- $answer_class = apply_filters( 'qsm_answer_wrapper_class', '', $answer, $id );
130
- if ( 'rich' === $answerEditor ) {
131
- ?>
132
- <div class='qmn_mc_answer_wrap <?php echo esc_attr( $answer_class ); ?>' id='question<?php echo esc_attr( $id ); ?>-<?php echo esc_attr( $mlw_answer_total ); ?>'>
133
- <?php
134
- } elseif ( 'image' === $answerEditor ) {
135
- ?>
136
- <div class='qmn_mc_answer_wrap qmn_image_option <?php echo esc_attr( $answer_class ); ?>' id='question<?php echo esc_attr( $id ); ?>-<?php echo esc_attr( $mlw_answer_total ); ?>'>
137
- <?php
138
- } else {
139
- ?>
140
- <div class="qmn_mc_answer_wrap <?php echo esc_attr( $answer_class ); ?>" id="<?php echo esc_attr( 'question' . $id . '-' . str_replace( ' ', '-', $answer[0] ) ); ?> ">
141
- <?php
142
- }
143
- ?>
144
- <input type='radio' class='qmn_quiz_radio' name="<?php echo esc_attr( 'question' . $id ); ?>" id="<?php echo esc_attr( 'question' . $id . '_' . $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer[0] ); ?>" />
145
- <label for="<?php echo esc_attr( 'question' . $id . '_' . $mlw_answer_total ); ?>">
146
- <?php
147
- if ( 'image' === $answerEditor ) {
148
- ?>
149
- <img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
150
- <span class="qsm_image_caption">
151
- <?php echo esc_html( trim( htmlspecialchars_decode( $answer[3], ENT_QUOTES ) ) ); ?>
152
- </span>
153
- <?php
154
- } else {
155
- echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
156
- }
157
- ?>
158
- </label>
159
- <?php
160
- echo apply_filters( 'qsm_multiple_choice_display_loop', ' ', $id, $question, $answers );
161
- ?>
162
- </div>
163
- <?php
164
- }
165
- }
166
- ?>
167
- <input type="radio" style="display: none;" name="<?php echo esc_attr( 'question' . $id ); ?>" id="<?php echo esc_attr( 'question' . $id . '_none' ); ?>" checked="checked" value="" />
168
- <?php
169
- }
170
- ?>
171
- </div>
172
- <?php
173
- echo apply_filters( 'qmn_multiple_choice_display_front', '', $id, $question, $answers );
174
- }
175
-
176
- /**
177
- * This function determines how the multiple choice question is graded.
178
- *
179
- * @params $id The ID of the multiple choice question
180
- * @params $question The question that is being edited.
181
- * @params @answers The array that contains the answers to the question.
182
- * @return $return_array Returns the graded question to the results page
183
- * @since 4.4.0
184
- */
185
- function qmn_multiple_choice_review( $id, $question, $answers ) {
186
- global $mlwQuizMasterNext;
187
- $return_array = array(
188
- 'points' => 0,
189
- 'correct' => 'incorrect',
190
- 'user_text' => '',
191
- 'correct_text' => '',
192
- );
193
- $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
194
- if ( isset( $_POST[ 'question' . $id ] ) ) {
195
- $mlw_user_answer = sanitize_text_field( wp_unslash( $_POST[ 'question' . $id ] ) );
196
- $mlw_user_answer = trim( stripslashes( htmlspecialchars_decode( $mlw_user_answer, ENT_QUOTES ) ) );
197
- } else {
198
- $mlw_user_answer = ' ';
199
- }
200
- $return_array['user_text'] = stripslashes( htmlspecialchars_decode( $mlw_user_answer, ENT_QUOTES ) );
201
- $rich_text_comapre = preg_replace( "/\s+|\n+|\r/", ' ', htmlentities( $mlw_user_answer ) );
202
- $correct_text = array();
203
- foreach ( $answers as $answer ) {
204
- if ( 'rich' === $answerEditor ) {
205
- $answer_option = trim( stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) );
206
- $sinel_answer_cmp = preg_replace( "/\s+|\n+|\r/", ' ', htmlentities( $answer_option ) );
207
- if ( $rich_text_comapre == $sinel_answer_cmp ) {
208
- $return_array['points'] = $answer[1];
209
- $return_array['user_text'] = $answer[0];
210
- if ( 1 == $answer[2] ) {
211
- $return_array['correct'] = 'correct';
212
- }
213
- }
214
- if ( 1 == $answer[2] ) {
215
- $correct_text[] = trim( stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) );
216
- }
217
- } else {
218
- $mlw_user_answer = '';
219
- if ( isset( $_POST[ 'question' . $id ] ) ) {
220
- $mlw_user_answer = sanitize_text_field( wp_unslash( $_POST[ 'question' . $id ] ) );
221
- $mlw_user_answer = trim( htmlspecialchars_decode( $mlw_user_answer, ENT_QUOTES ) );
222
- $mlw_user_answer = str_replace( '\\', '', $mlw_user_answer );
223
- }
224
- $single_answer = trim( htmlspecialchars_decode( sanitize_text_field( $answer[0], ENT_QUOTES ) ) );
225
- $single_answer = str_replace( '\\', '', $single_answer );
226
- if ( $mlw_user_answer == $single_answer ) {
227
- $return_array['points'] = $answer[1];
228
- $return_array['user_text'] = $answer[0];
229
- if ( 1 == $answer[2] ) {
230
- $return_array['correct'] = 'correct';
231
- }
232
- }
233
- if ( 1 == $answer[2] ) {
234
- $correct_text[] = stripslashes( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) );
235
- }
236
- }
237
- }
238
- $return_array['correct_text'] = implode( '.', $correct_text );
239
- /**
240
- * Hook to filter answers array
241
- */
242
- return apply_filters( 'qmn_multiple_choice_review', $return_array, $answers );
243
  }
244
-
245
- add_action( 'plugins_loaded', 'qmn_question_type_date' );
246
  /**
247
  * Registers the date type
248
  *
@@ -250,76 +90,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_date' );
250
  * @since 6.3.7
251
  */
252
  function qmn_question_type_date() {
253
- global $mlwQuizMasterNext;
254
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Date', 'quiz-master-next' ), 'qmn_date_display', true, 'qmn_date_review', null, null, 12 );
255
- }
256
-
257
- /**
258
- * This function shows the content of the date field
259
- *
260
- * @params $id The ID of the multiple choice question
261
- * @params $question The question that is being edited.
262
- * @params @answers The array that contains the answers to the question.
263
- *
264
- * @since 6.3.7
265
- */
266
- function qmn_date_display( $id, $question, $answers ) {
267
- global $mlwQuizMasterNext;
268
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
269
- if ( 0 == $required ) {
270
- $mlw_require_class = 'mlwRequiredDate';
271
- } else {
272
- $mlw_require_class = '';
273
- }
274
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
275
- qsm_question_title_func( $question, '', $new_question_title, $id );
276
- ?>
277
- <input type="date" class="mlw_answer_date <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ); ?>" value="" />
278
- <?php
279
- echo apply_filters( 'qmn_date_display_front', '', $id, $question, $answers );
280
- }
281
-
282
- /**
283
- * This function reviews the date type.
284
- *
285
- * @params $id The ID of the multiple choice question
286
- * @params $question The question that is being edited.
287
- * @params @answers The array that contains the answers to the question.
288
- * @return $return_array Returns the graded question to the results page
289
- * @since 6.3.7
290
- */
291
- function qmn_date_review( $id, $question, $answers ) {
292
- $return_array = array(
293
- 'points' => 0,
294
- 'correct' => 'incorrect',
295
- 'user_text' => '',
296
- 'correct_text' => '',
297
- );
298
- if ( isset( $_POST[ 'question' . $id ] ) ) {
299
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
300
- $decode_user_answer = htmlspecialchars_decode( $question_input, ENT_QUOTES );
301
- $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
302
- } else {
303
- $mlw_user_answer = ' ';
304
- }
305
- $return_array['user_text'] = $mlw_user_answer;
306
- foreach ( $answers as $answer ) {
307
- $decode_correct_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
308
- $return_array['correct_text'] = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_correct_text ) ) );
309
- if ( mb_strtoupper( $return_array['user_text'] ) == mb_strtoupper( $return_array['correct_text'] ) ) {
310
- $return_array['correct'] = 'correct';
311
- $return_array['points'] = $answer[1];
312
- break;
313
- }
314
- }
315
- /**
316
- * Hook to filter answers array
317
- */
318
- return apply_filters( 'qmn_date_review', $return_array, $answers );
319
  }
320
-
321
- add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_choice' );
322
-
323
  /**
324
  * This function registers the horizontal multiple choice type.
325
  *
@@ -327,141 +102,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_choice' );
327
  * @since 4.4.0
328
  */
329
  function qmn_question_type_horizontal_multiple_choice() {
330
- global $mlwQuizMasterNext;
331
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Horizontal Multiple Choice', 'quiz-master-next' ), 'qmn_horizontal_multiple_choice_display', true, 'qmn_horizontal_multiple_choice_review', null, null, 1 );
332
- }
333
-
334
- /**
335
- * This function shows the content of the horizontal multiple choice question.
336
- *
337
- * @params $id The ID of the multiple choice question
338
- * @params $question The question that is being edited.
339
- * @params @answers The array that contains the answers to the question.
340
- *
341
- * @since 4.4.0
342
- */
343
- function qmn_horizontal_multiple_choice_display( $id, $question, $answers ) {
344
- global $mlwQuizMasterNext;
345
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
346
- if ( 0 == $required ) {
347
- $mlw_require_class = 'mlwRequiredRadio';
348
- } else {
349
- $mlw_require_class = '';
350
- }
351
- $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
352
- // $question_title = apply_filters('the_content', $question);
353
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
354
- qsm_question_title_func( $question, 'horizontal_multiple_choice', $new_question_title, $id );
355
- ?>
356
- <div class="qmn_radio_answers qmn_radio_horizontal_answers <?php echo esc_attr( $mlw_require_class ); ?>">
357
- <?php
358
- if ( is_array( $answers ) ) {
359
- $mlw_answer_total = 0;
360
- foreach ( $answers as $answer_index => $answer ) {
361
- $mlw_answer_total++;
362
- if ( '' !== $answer[0] ) {
363
- $answer_class = apply_filters( 'qsm_answer_wrapper_class', '', $answer, $id );
364
- ?>
365
- <span class="mlw_horizontal_choice <?php echo esc_attr( $answer_class ); ?>"><input type="radio" class="qmn_quiz_radio" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer[0] ); ?>" />
366
- <label for="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>">
367
- <?php
368
- if ( 'image' === $answerEditor ) {
369
- ?>
370
- <img alt="<?php echo esc_attr( $new_question_title ); ?>" src=" <?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
371
- <?php
372
- } else {
373
- echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
374
- }
375
- ?>
376
- </label>
377
- <?php
378
- echo apply_filters( 'qsm_multiple_choice_horizontal_display_loop', '', $id, $question, $answers );
379
- ?>
380
- </span>
381
- <?php
382
- }
383
- }
384
- echo apply_filters( 'qmn_horizontal_multiple_choice_question_display', '', $id, $question, $answers );
385
- ?>
386
- <input type="radio" style="display: none;" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ); ?>_none" checked="checked" value="" />
387
- <?php
388
- }
389
- ?>
390
- </div>
391
- <?php
392
- echo apply_filters( 'qmn_horizontal_multiple_choice_display_front', '', $id, $question, $answers );
393
- }
394
-
395
- /**
396
- * This function determines how the question is graded.
397
- *
398
- * @params $id The ID of the multiple choice question
399
- * @params $question The question that is being edited.
400
- * @params @answers The array that contains the answers to the question.
401
- * @return $return_array Returns the graded question to the results page
402
- * @since 4.4.0
403
- */
404
- function qmn_horizontal_multiple_choice_review( $id, $question, $answers ) {
405
- global $mlwQuizMasterNext;
406
- $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
407
- $return_array = array(
408
- 'points' => 0,
409
- 'correct' => 'incorrect',
410
- 'user_text' => '',
411
- 'correct_text' => '',
412
- );
413
- if ( isset( $_POST[ 'question' . $id ] ) ) {
414
- $mlw_user_answer = sanitize_text_field( wp_unslash( $_POST[ 'question' . $id ] ) );
415
- $mlw_user_answer = trim( stripslashes( htmlspecialchars_decode( $mlw_user_answer, ENT_QUOTES ) ) );
416
- } else {
417
- $mlw_user_answer = ' ';
418
- }
419
- $rich_text_comapre = preg_replace( "/\s+|\n+|\r/", ' ', htmlentities( $mlw_user_answer ) );
420
- $correct_text = array();
421
- foreach ( $answers as $answer ) {
422
- if ( 'rich' === $answerEditor ) {
423
- $answer_option = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
424
- $sinel_answer_cmp = preg_replace( "/\s+|\n+|\r/", ' ', htmlentities( $answer_option ) );
425
- if ( $rich_text_comapre == $sinel_answer_cmp ) {
426
- $return_array['points'] = $answer[1];
427
- $return_array['user_text'] = $answer[0];
428
- if ( 1 == $answer[2] ) {
429
- $return_array['correct'] = 'correct';
430
- }
431
- }
432
- if ( 1 == $answer[2] ) {
433
- $correct_text[] = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
434
- }
435
- } else {
436
- $mlw_user_answer = '';
437
- if ( isset( $_POST[ 'question' . $id ] ) ) {
438
- $mlw_user_answer = sanitize_text_field( wp_unslash( $_POST[ 'question' . $id ] ) );
439
- $mlw_user_answer = trim( htmlspecialchars_decode( $mlw_user_answer, ENT_QUOTES ) );
440
- $mlw_user_answer = str_replace( '\\', '', $mlw_user_answer );
441
- }
442
- $single_answer = trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
443
- $single_answer = str_replace( '\\', '', $single_answer );
444
- if ( $mlw_user_answer == $single_answer ) {
445
- $return_array['points'] = $answer[1];
446
- $return_array['user_text'] = $answer[0];
447
- if ( 1 == $answer[2] ) {
448
- $return_array['correct'] = 'correct';
449
- }
450
- }
451
- if ( 1 == $answer[2] ) {
452
- $correct_text[] = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
453
- }
454
- }
455
- }
456
- $return_array['correct_text'] = implode( '.', $correct_text );
457
- /**
458
- * Hook to filter answers array
459
- */
460
- return apply_filters( 'qmn_horizontal_multiple_choice_review', $return_array, $answers );
461
  }
462
-
463
- add_action( 'plugins_loaded', 'qmn_question_type_drop_down' );
464
-
465
  /**
466
  * This function registers the drop down question type
467
  *
@@ -469,95 +114,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_drop_down' );
469
  * @since 4.4.0
470
  */
471
  function qmn_question_type_drop_down() {
472
- global $mlwQuizMasterNext;
473
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Drop Down', 'quiz-master-next' ), 'qmn_drop_down_display', true, 'qmn_drop_down_review', null, null, 2 );
474
- }
475
-
476
- /**
477
- * This function shows the content of the multiple choice question.
478
- *
479
- * @params $id The ID of the multiple choice question
480
- * @params $question The question that is being edited.
481
- * @params @answers The array that contains the answers to the question.
482
- *
483
- * @since 4.4.0
484
- */
485
- function qmn_drop_down_display( $id, $question, $answers ) {
486
- global $mlwQuizMasterNext;
487
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
488
- if ( 0 == $required ) {
489
- $require_class = 'qsmRequiredSelect';
490
- } else {
491
- $require_class = '';
492
- }
493
- // $question_title = apply_filters('the_content', $question);
494
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
495
- qsm_question_title_func( $question, '', $new_question_title, $id );
496
- ?>
497
- <select class="qsm_select <?php echo esc_attr( $require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>"><option value=""><?php echo esc_html__( 'Please select your answer', 'quiz-master-next' ); ?></option>
498
- <?php
499
- if ( is_array( $answers ) ) {
500
- $mlw_answer_total = 0;
501
- foreach ( $answers as $answer ) {
502
- $mlw_answer_total++;
503
- if ( '' !== $answer[0] ) {
504
- ?>
505
- <option value="<?php echo esc_attr( $answer[0] ); ?>"><?php echo esc_html( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ); ?></option>
506
- <?php
507
- }
508
- }
509
- }
510
- ?>
511
- </select>
512
- <?php
513
- echo apply_filters( 'qmn_drop_down_display_front', '', $id, $question, $answers );
514
- }
515
-
516
- /**
517
- * This function determines how the question is graded
518
- *
519
- * @params $id The ID of the multiple choice question
520
- * @params $question The question that is being edited.
521
- * @params @answers The array that contains the answers to the question.
522
- * @return $return_array Returns the graded question to the results page
523
- * @since 4.4.0
524
- */
525
- function qmn_drop_down_review( $id, $question, $answers ) {
526
- global $mlwQuizMasterNext;
527
- $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
528
- $return_array = array(
529
- 'points' => 0,
530
- 'correct' => 'incorrect',
531
- 'user_text' => '',
532
- 'correct_text' => '',
533
- );
534
- if ( isset( $_POST[ 'question' . $id ] ) ) {
535
- $mlw_user_answer = sanitize_text_field( wp_unslash( $_POST[ 'question' . $id ] ) );
536
- $mlw_user_answer = trim( stripslashes( htmlspecialchars_decode( $mlw_user_answer, ENT_QUOTES ) ) );
537
- } else {
538
- $mlw_user_answer = ' ';
539
- }
540
- foreach ( $answers as $answer ) {
541
- $answers_loop = trim( stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) );
542
- if ( $mlw_user_answer == $answers_loop ) {
543
- $return_array['points'] = $answer[1];
544
- $return_array['user_text'] = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
545
- if ( 1 == $answer[2] ) {
546
- $return_array['correct'] = 'correct';
547
- }
548
- }
549
- if ( 1 == $answer[2] ) {
550
- $return_array['correct_text'] = htmlspecialchars_decode( $answer[0], ENT_QUOTES );
551
- }
552
- }
553
- /**
554
- * Hook to filter answers array
555
- */
556
- return apply_filters( 'qmn_drop_down_review', $return_array, $answers );
557
  }
558
-
559
- add_action( 'plugins_loaded', 'qmn_question_type_small_open' );
560
-
561
  /**
562
  * This function registers the small open question type
563
  *
@@ -565,81 +126,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_small_open' );
565
  * @since 4.4.0
566
  */
567
  function qmn_question_type_small_open() {
568
- global $mlwQuizMasterNext;
569
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Short Answer', 'quiz-master-next' ), 'qmn_small_open_display', true, 'qmn_small_open_review', null, null, 3 );
570
- }
571
-
572
- /**
573
- * This function shows the content of the small open answer question.
574
- *
575
- * @params $id The ID of the multiple choice question
576
- * @params $question The question that is being edited.
577
- * @params @answers The array that contains the answers to the question.
578
- *
579
- * @since 4.4.0
580
- */
581
- function qmn_small_open_display( $id, $question, $answers ) {
582
- global $mlwQuizMasterNext;
583
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
584
- $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
585
- $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
586
- $autofill_att = $autofill ? "autocomplete='off' " : '';
587
- $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
588
- if ( 0 == $required ) {
589
- $mlw_require_class = 'mlwRequiredText';
590
- } else {
591
- $mlw_require_class = '';
592
- }
593
- // $question_title = apply_filters('the_content', $question);
594
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
595
- qsm_question_title_func( $question, '', $new_question_title, $id );
596
- ?>
597
- <input <?php echo esc_attr( $autofill_att . $limit_text_att ); ?> type="text" class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" />
598
- <?php
599
- echo apply_filters( 'qmn_small_open_display_front', '', $id, $question, $answers );
600
- }
601
-
602
- /**
603
- * This function reviews the small open answer.
604
- *
605
- * @params $id The ID of the multiple choice question
606
- * @params $question The question that is being edited.
607
- * @params @answers The array that contains the answers to the question.
608
- * @return $return_array Returns the graded question to the results page
609
- * @since 4.4.0
610
- */
611
- function qmn_small_open_review( $id, $question, $answers ) {
612
- $return_array = array(
613
- 'points' => 0,
614
- 'correct' => 'incorrect',
615
- 'user_text' => '',
616
- 'correct_text' => '',
617
- );
618
- if ( isset( $_POST[ 'question' . $id ] ) ) {
619
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
620
- $decode_user_answer = htmlspecialchars_decode( $question_input, ENT_QUOTES );
621
- $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
622
- } else {
623
- $mlw_user_answer = ' ';
624
- }
625
- $return_array['user_text'] = $mlw_user_answer;
626
- foreach ( $answers as $answer ) {
627
- $decode_correct_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
628
- $return_array['correct_text'] = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_correct_text ) ) );
629
- if ( mb_strtoupper( $return_array['user_text'] ) == mb_strtoupper( $return_array['correct_text'] ) ) {
630
- $return_array['correct'] = 'correct';
631
- $return_array['points'] = $answer[1];
632
- break;
633
- }
634
- }
635
- /**
636
- * Hook to filter answers array
637
- */
638
- return apply_filters( 'qmn_small_open_review', $return_array, $answers );
639
  }
640
-
641
- add_action( 'plugins_loaded', 'qmn_question_type_multiple_response' );
642
-
643
  /**
644
  * This function registers the multiple response question type
645
  *
@@ -647,198 +138,22 @@ add_action( 'plugins_loaded', 'qmn_question_type_multiple_response' );
647
  * @since 4.4.0
648
  */
649
  function qmn_question_type_multiple_response() {
650
- global $mlwQuizMasterNext;
651
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Multiple Response', 'quiz-master-next' ), 'qmn_multiple_response_display', true, 'qmn_multiple_response_review', null, null, 4 );
652
- }
653
-
654
- /**
655
- * This function shows the content of the multiple response question
656
- *
657
- * @params $id The ID of the multiple choice question
658
- * @params $question The question that is being edited.
659
- * @params @answers The array that contains the answers to the question.
660
- *
661
- * @since 4.4.0
662
- */
663
- function qmn_multiple_response_display( $id, $question, $answers ) {
664
- $limit_mr_text = '';
665
- global $mlwQuizMasterNext;
666
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
667
- $limit_multiple_response = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_multiple_response' );
668
- if ( $limit_multiple_response > 0 ) {
669
- $limit_mr_text = 'onchange="qsmCheckMR(this,' . $limit_multiple_response . ')"';
670
- }
671
- if ( 0 == $required ) {
672
- $mlw_require_class = 'mlwRequiredCheck';
673
- } else {
674
- $mlw_require_class = '';
675
- }
676
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
677
- $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
678
- qsm_question_title_func( $question, '', $new_question_title, $id );
679
- ?>
680
- <div class="qmn_check_answers <?php echo esc_attr( $mlw_require_class ); ?>">
681
- <?php
682
- if ( is_array( $answers ) ) {
683
- $mlw_answer_total = 0;
684
- foreach ( $answers as $answer ) {
685
- $mlw_answer_total++;
686
- if ( '' !== $answer[0] ) {
687
- ?>
688
- <div class="qsm_check_answer">
689
- <input type="hidden" name="question<?php echo esc_attr( $id ); ?>" value="This value does not matter" />
690
- <input type="checkbox" <?php echo esc_attr( $limit_mr_text ); ?> name="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer[0] ); ?> " /> <label for="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>">
691
- <?php
692
- if ( 'image' === $answerEditor ) {
693
- ?>
694
- <img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
695
- <?php
696
- } else {
697
- echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
698
- }
699
- ?>
700
- </label>
701
- </div>
702
- <?php
703
- }
704
- }
705
- }
706
- ?>
707
- </div>
708
- <?php
709
- echo apply_filters( 'qmn_multiple_response_display_front', '', $id, $question, $answers );
710
- }
711
-
712
- /**
713
- * This function determines how the multiple response is graded,
714
- *
715
- * @params $id The ID of the multiple choice question
716
- * @params $question The question that is being edited.
717
- * @params @answers The array that contains the answers to the question.
718
- * @return $return_array Returns the graded question to the results page
719
- * @since 4.4.0
720
- */
721
- function qmn_multiple_response_review( $id, $question, $answers ) {
722
- $return_array = array(
723
- 'points' => 0,
724
- 'correct' => 'incorrect',
725
- 'user_text' => '',
726
- 'correct_text' => '',
727
- 'user_compare_text' => '',
728
- );
729
- $user_correct = 0;
730
- $total_correct = 0;
731
- $total_answers = count( $answers );
732
- $correct_text = array();
733
- foreach ( $answers as $answer ) {
734
- for ( $i = 1; $i <= $total_answers; $i++ ) {
735
- if ( isset( $_POST[ 'question' . $id . '_' . $i ] ) && htmlspecialchars( sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id . '_' . $i ] ) ), ENT_QUOTES ) == esc_attr( $answer[0] ) ) {
736
- $return_array['points'] += $answer[1];
737
- $return_array['user_text'] .= htmlspecialchars_decode( $answer[0], ENT_QUOTES ) . '.';
738
- $return_array['user_compare_text'] .= sanitize_textarea_field( strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) . '=====';
739
- if ( 1 == $answer[2] ) {
740
- $user_correct += 1;
741
- } else {
742
- $user_correct = -1;
743
- }
744
- }
745
- }
746
- if ( 1 == $answer[2] ) {
747
- $correct_text[] = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
748
- $total_correct++;
749
- }
750
- }
751
- if ( $user_correct == $total_correct ) {
752
- $return_array['correct'] = 'correct';
753
- }
754
- $return_array['correct_text'] = implode( '.', $correct_text );
755
- /**
756
- * Hook to filter answers array
757
- */
758
- return apply_filters( 'qmn_multiple_response_review', $return_array, $answers );
759
  }
760
-
761
- add_action( 'plugins_loaded', 'qmn_question_type_large_open' );
762
-
763
  /**
764
  * This function registers the large open question type.
765
  *
766
  * @since 4.4.0
767
  */
768
  function qmn_question_type_large_open() {
769
- global $mlwQuizMasterNext;
770
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Paragraph', 'quiz-master-next' ), 'qmn_large_open_display', true, 'qmn_large_open_review', null, null, 5 );
771
- }
772
-
773
- /**
774
- * This function displays the content of the large open question.
775
- *
776
- * @params $id The ID of the multiple choice question
777
- * @params $question The question that is being edited.
778
- * @params @answers The array that contains the answers to the question.
779
- *
780
- * @since 4.4.0
781
- */
782
- function qmn_large_open_display( $id, $question, $answers ) {
783
- global $mlwQuizMasterNext;
784
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
785
- $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
786
- if ( 0 == $required ) {
787
- $mlw_require_class = 'mlwRequiredText';
788
- } else {
789
- $mlw_require_class = '';
790
- }
791
- $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
792
- // $question_title = apply_filters('the_content', $question);
793
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
794
- qsm_question_title_func( $question, '', $new_question_title, $id );
795
- ?>
796
- <textarea class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" <?php echo esc_attr( $limit_text_att ); ?> cols="70" rows="5" name="question<?php echo esc_attr( $id ); ?>" /></textarea>
797
- <?php
798
- echo apply_filters( 'qmn_large_open_display_front', '', $id, $question, $answers );
799
- }
800
-
801
- /**
802
- * This function determines how the large open question is graded
803
- *
804
- * @params $id The ID of the multiple choice question
805
- * @params $question The question that is being edited.
806
- * @params @answers The array that contains the answers to the question.
807
- * @return $return_array Returns the graded question to the results page
808
- * @since 4.4.0
809
- */
810
- function qmn_large_open_review( $id, $question, $answers ) {
811
- $return_array = array(
812
- 'points' => 0,
813
- 'correct' => 'incorrect',
814
- 'user_text' => '',
815
- 'correct_text' => '',
816
- );
817
- if ( isset( $_POST[ 'question' . $id ] ) ) {
818
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
819
- $decode_user_answer = strval( htmlspecialchars_decode( $question_input, ENT_QUOTES ) );
820
- $mlw_user_answer = trim( str_replace( ' ', '', preg_replace( '/\s\s+/', '', $decode_user_answer ) ) );
821
- } else {
822
- $mlw_user_answer = ' ';
823
- }
824
- $return_array['user_text'] = $decode_user_answer;
825
- foreach ( $answers as $answer ) {
826
- $return_array['correct_text'] = $decode_correct_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
827
- $decode_correct_text = trim( str_replace( ' ', '', preg_replace( '/\s\s+/', '', $decode_correct_text ) ) );
828
- if ( mb_strtoupper( $mlw_user_answer ) == mb_strtoupper( $decode_correct_text ) ) {
829
- $return_array['correct'] = 'correct';
830
- $return_array['points'] = $answer[1];
831
- break;
832
- }
833
- }
834
- /**
835
- * Hook to filter answers array
836
- */
837
- return apply_filters( 'qmn_large_open_review', $return_array, $answers );
838
  }
839
-
840
- add_action( 'plugins_loaded', 'qmn_question_type_text_block' );
841
-
842
  /**
843
  * This function registers the text block question type
844
  *
@@ -846,33 +161,19 @@ add_action( 'plugins_loaded', 'qmn_question_type_text_block' );
846
  * @since 4.4.0
847
  */
848
  function qmn_question_type_text_block() {
849
- global $mlwQuizMasterNext;
850
- $edit_args = array(
851
- 'inputs' => array(
852
- 'question',
853
- ),
854
- 'information' => '',
855
- 'extra_inputs' => array(),
856
- 'function' => '',
857
- );
858
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Text/HTML Section', 'quiz-master-next' ), 'qmn_text_block_display', false, null, $edit_args, null, 6 );
859
- }
860
-
861
- /**
862
- * This function displays the contents of the text block question type.
863
- *
864
- * @params $id The ID of the multiple choice question
865
- * @params $question The question that is being edited.
866
- * @params @answers The array that contains the answers to the question.
867
- *
868
- * @since 4.4.0
869
- */
870
- function qmn_text_block_display( $id, $question, $answers ) {
871
- echo wp_kses_post( do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
872
  }
873
-
874
- add_action( 'plugins_loaded', 'qmn_question_type_number' );
875
-
876
  /**
877
  * This function registers the number question type
878
  *
@@ -883,77 +184,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_number' );
883
  * @since 4.4.0
884
  */
885
  function qmn_question_type_number() {
886
- global $mlwQuizMasterNext;
887
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Number', 'quiz-master-next' ), 'qmn_number_display', true, 'qmn_number_review', null, null, 7 );
888
- }
889
-
890
- /**
891
- * This function shows the content of the multiple choice question.
892
- *
893
- * @params $id The ID of the multiple choice question
894
- * @params $question The question that is being edited.
895
- * @params @answers The array that contains the answers to the question.
896
- *
897
- * @since 4.4.0
898
- */
899
- function qmn_number_display( $id, $question, $answers ) {
900
- global $mlwQuizMasterNext;
901
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
902
- $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
903
- $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' oninput='javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);'" : '';
904
- if ( 0 == $required ) {
905
- $mlw_require_class = 'mlwRequiredNumber';
906
- } else {
907
- $mlw_require_class = '';
908
- }
909
- // $question_title = apply_filters('the_content', $question);
910
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
911
- qsm_question_title_func( $question, '', $new_question_title, $id );
912
- ?>
913
- <input type="number" <?php echo esc_attr( $limit_text_att ); ?> class="mlw_answer_number <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" />
914
- <?php
915
- echo apply_filters( 'qmn_number_display_front', '', $id, $question, $answers );
916
- }
917
-
918
- /**
919
- * This function determines how the number question type is graded.
920
- *
921
- * @params $id The ID of the multiple choice question
922
- * @params $question The question that is being edited.
923
- * @params @answers The array that contains the answers to the question.
924
- * @return $return_array Returns the graded question to the results page
925
- * @since 4.4.0
926
- */
927
- function qmn_number_review( $id, $question, $answers ) {
928
- $return_array = array(
929
- 'points' => 0,
930
- 'correct' => 'incorrect',
931
- 'user_text' => '',
932
- 'correct_text' => '',
933
- );
934
- if ( isset( $_POST[ 'question' . $id ] ) ) {
935
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
936
- $mlw_user_answer = htmlspecialchars_decode( $question_input, ENT_QUOTES );
937
- } else {
938
- $mlw_user_answer = ' ';
939
- }
940
- $return_array['user_text'] = $mlw_user_answer;
941
- foreach ( $answers as $answer ) {
942
- $return_array['correct_text'] = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
943
- if ( strtoupper( $return_array['user_text'] ) == strtoupper( $return_array['correct_text'] ) ) {
944
- $return_array['correct'] = 'correct';
945
- $return_array['points'] = $answer[1];
946
- break;
947
- }
948
- }
949
- /**
950
- * Hook to filter answers array
951
- */
952
- return apply_filters( 'qmn_number_review', $return_array, $answers );
953
  }
954
-
955
- add_action( 'plugins_loaded', 'qmn_question_type_accept' );
956
-
957
  /**
958
  * This function registers the accept question type.
959
  *
@@ -961,99 +196,40 @@ add_action( 'plugins_loaded', 'qmn_question_type_accept' );
961
  * @since 4.4.0
962
  */
963
  function qmn_question_type_accept() {
964
- global $mlwQuizMasterNext;
965
- $edit_args = array(
966
- 'inputs' => array(
967
- 'question',
968
- 'required',
969
- ),
970
- 'information' => '',
971
- 'extra_inputs' => array(),
972
- 'function' => '',
973
- );
974
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Opt-in', 'quiz-master-next' ), 'qmn_accept_display', false, null, $edit_args, null, 8 );
975
- }
976
-
977
- /**
978
- * This function displays the accept question
979
- *
980
- * @params $id The ID of the multiple choice question
981
- * @params $question The question that is being edited.
982
- * @params @answers The array that contains the answers to the question.
983
- *
984
- * @since 4.4.0
985
- */
986
- function qmn_accept_display( $id, $question, $answers ) {
987
- global $mlwQuizMasterNext;
988
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
989
- if ( 0 == $required ) {
990
- $mlw_require_class = 'mlwRequiredAccept';
991
- } else {
992
- $mlw_require_class = '';
993
- }
994
- ?>
995
- <div class="qmn_accept_answers">
996
- <input type="checkbox" id="mlwAcceptance" class="<?php echo esc_attr( $mlw_require_class ); ?>" />
997
- <label for="mlwAcceptance"><span class="qmn_accept_text"><?php echo wp_kses_post( do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) ); ?></span></label>
998
- </div>
999
- <?php
1000
- echo apply_filters( 'qmn_accept_display_front', '', $id, $question, $answers );
1001
  }
1002
-
1003
- add_action( 'plugins_loaded', 'qmn_question_type_captcha' );
1004
-
1005
  /**
1006
  * This function registers the captcha question
1007
  *
1008
  * @since 4.4.0
1009
  */
1010
  function qmn_question_type_captcha() {
1011
- global $mlwQuizMasterNext;
1012
- $edit_args = array(
1013
- 'inputs' => array(
1014
- 'question',
1015
- 'required',
1016
- ),
1017
- 'information' => '',
1018
- 'extra_inputs' => array(),
1019
- 'function' => '',
1020
- );
1021
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Captcha', 'quiz-master-next' ), 'qmn_captcha_display', false, null, $edit_args, null, 9 );
1022
- }
1023
-
1024
- /**
1025
- * This function displays the captcha question
1026
- *
1027
- * @params $id The ID of the multiple choice question
1028
- * @params $question The question that is being edited.
1029
- * @params @answers The array that contains the answers to the question.
1030
- *
1031
- * @since 4.4.0
1032
- */
1033
- function qmn_captcha_display( $id, $question, $answers ) {
1034
- global $mlwQuizMasterNext;
1035
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
1036
- if ( 0 == $required ) {
1037
- $mlw_require_class = 'mlwRequiredCaptcha';
1038
- } else {
1039
- $mlw_require_class = '';
1040
- }
1041
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
1042
- ?>
1043
- <span class="mlw_qmn_question">
1044
- <?php qsm_question_title_func( $question, '', $new_question_title, $id ); ?>
1045
- </span>
1046
- <div class="mlw_captchaWrap">
1047
- <canvas alt="" id="mlw_captcha" class="mlw_captcha" width="100" height="50"></canvas>
1048
- </div>
1049
- <input type="text" class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" id="mlw_captcha_text" name="mlw_user_captcha"/>
1050
- <input type="hidden" name="mlw_code_captcha" id="mlw_code_captcha" value="none" />
1051
- <?php
1052
- echo apply_filters( 'qmn_captcha_display_front', '', $id, $question, $answers );
1053
  }
1054
-
1055
- add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_response' );
1056
-
1057
  /**
1058
  * This function registers the horizontal multiple response question
1059
  *
@@ -1061,120 +237,11 @@ add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_response' )
1061
  * @since 4.4.0
1062
  */
1063
  function qmn_question_type_horizontal_multiple_response() {
1064
- global $mlwQuizMasterNext;
1065
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Horizontal Multiple Response', 'quiz-master-next' ), 'qmn_horizontal_multiple_response_display', true, 'qmn_horizontal_multiple_response_review', null, null, 10 );
1066
- }
1067
-
1068
- /**
1069
- * This function displays the content of the multiple response question type
1070
- *
1071
- * @params $id The ID of the multiple choice question
1072
- * @params $question The question that is being edited.
1073
- * @params @answers The array that contains the answers to the question.
1074
- *
1075
- * @since 4.4.0
1076
- */
1077
- function qmn_horizontal_multiple_response_display( $id, $question, $answers ) {
1078
- global $mlwQuizMasterNext;
1079
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
1080
- if ( 0 == $required ) {
1081
- $mlw_require_class = 'mlwRequiredCheck';
1082
- } else {
1083
- $mlw_require_class = '';
1084
- }
1085
- // $question_title = apply_filters('the_content', $question);
1086
- $limit_multiple_response = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_multiple_response' );
1087
- $limit_mr_text = '';
1088
- if ( $limit_multiple_response > 0 ) {
1089
- $limit_mr_text = 'onchange="qsmCheckMR(this,' . $limit_multiple_response . ')"';
1090
- }
1091
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
1092
- $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
1093
- qsm_question_title_func( $question, '', $new_question_title, $id );
1094
- ?>
1095
- <div class="qmn_check_answers qmn_multiple_horizontal_check <?php echo esc_attr( $mlw_require_class ); ?>">
1096
- <?php
1097
- if ( is_array( $answers ) ) {
1098
- $mlw_answer_total = 0;
1099
- foreach ( $answers as $answer ) {
1100
- $mlw_answer_total++;
1101
- if ( '' !== $answer[0] ) {
1102
- ?>
1103
- <input type="hidden" name="question<?php echo esc_attr( $id ); ?> " value="This value does not matter" />
1104
- <span class="mlw_horizontal_multiple"><input type="checkbox" <?php echo esc_attr( $limit_mr_text ); ?> name="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer[0] ); ?>" />
1105
- <label for="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>">
1106
- <?php
1107
- if ( 'image' === $answerEditor ) {
1108
- ?>
1109
- <img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
1110
- <?php
1111
- } else {
1112
- echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
1113
- }
1114
- ?>
1115
- </label>
1116
- </span>
1117
- <?php
1118
- }
1119
- }
1120
- }
1121
- ?>
1122
- </div>
1123
- <?php
1124
- echo apply_filters( 'qmn_horizontal_multiple_response_display_front', '', $id, $question, $answers );
1125
- }
1126
-
1127
- /**
1128
- * This function determines how the multiple response is graded.
1129
- *
1130
- * @params $id The ID of the multiple choice question
1131
- * @params $question The question that is being edited.
1132
- * @params @answers The array that contains the answers to the question.
1133
- * @return $return_array Returns the graded question to the Results page
1134
- * @since 4.4.0
1135
- */
1136
- function qmn_horizontal_multiple_response_review( $id, $question, $answers ) {
1137
- $return_array = array(
1138
- 'points' => 0,
1139
- 'correct' => 'incorrect',
1140
- 'user_text' => '',
1141
- 'correct_text' => '',
1142
- 'user_compare_text' => '',
1143
- );
1144
- $user_correct = 0;
1145
- $total_correct = 0;
1146
- $total_answers = count( $answers );
1147
- $correct_text = array();
1148
- foreach ( $answers as $answer ) {
1149
- for ( $i = 1; $i <= $total_answers; $i++ ) {
1150
- if ( isset( $_POST[ 'question' . $id . '_' . $i ] ) && htmlspecialchars( sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id . '_' . $i ] ) ), ENT_QUOTES ) == esc_attr( $answer[0] ) ) {
1151
- $return_array['points'] += $answer[1];
1152
- $return_array['user_text'] .= strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) . '.';
1153
- $return_array['user_compare_text'] .= sanitize_textarea_field( strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) . '=====';
1154
- if ( 1 == $answer[2] ) {
1155
- $user_correct += 1;
1156
- } else {
1157
- $user_correct = -1;
1158
- }
1159
- }
1160
- }
1161
- if ( 1 == $answer[2] ) {
1162
- $correct_text[] = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
1163
- $total_correct++;
1164
- }
1165
- }
1166
- if ( $user_correct == $total_correct ) {
1167
- $return_array['correct'] = 'correct';
1168
- }
1169
- $return_array['correct_text'] = implode( '.', $correct_text );
1170
- /**
1171
- * Hook to filter answers array
1172
- */
1173
- return apply_filters( 'qmn_horizontal_multiple_response_review', $return_array, $answers );
1174
  }
1175
-
1176
- add_action( 'plugins_loaded', 'qmn_question_type_fill_blank' );
1177
-
1178
  /**
1179
  * This function registers the fill in the blank question type
1180
  *
@@ -1182,303 +249,34 @@ add_action( 'plugins_loaded', 'qmn_question_type_fill_blank' );
1182
  * @since 4.4.0
1183
  */
1184
  function qmn_question_type_fill_blank() {
1185
- global $mlwQuizMasterNext;
1186
- $edit_args = array(
1187
- 'inputs' => array(
1188
- 'question',
1189
- 'answer',
1190
- 'hint',
1191
- 'correct_info',
1192
- 'comments',
1193
- 'category',
1194
- 'required',
1195
- ),
1196
- 'information' => __( 'For fill in the blank types, use %BLANK% to represent where to put the text box in your text.', 'quiz-master-next' ),
1197
- 'extra_inputs' => array(),
1198
- 'function' => '',
1199
- );
1200
-
1201
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Fill In The Blank', 'quiz-master-next' ), 'qmn_fill_blank_display', true, 'qmn_fill_blank_review', $edit_args, null, 14 );
1202
-
1203
- }
1204
-
1205
- /**
1206
- * This function displays the fill in the blank question
1207
- *
1208
- * @params $id The ID of the multiple choice question
1209
- * @params $question The question that is being edited.
1210
- * @params @answers The array that contains the answers to the question.
1211
- * @since 4.4.0
1212
- */
1213
- function qmn_fill_blank_display( $id, $question, $answers ) {
1214
- global $mlwQuizMasterNext;
1215
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
1216
- $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
1217
- $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
1218
- $autofill_att = $autofill ? "autocomplete='off' " : '';
1219
- $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
1220
- if ( 0 == $required ) {
1221
- $mlw_require_class = 'mlwRequiredText';
1222
- } else {
1223
- $mlw_require_class = '';
1224
- }
1225
- $input_text = '<input ' . $autofill_att . $limit_text_att . " type='text' class='qmn_fill_blank $mlw_require_class' name='question" . $id . "[]' />";
1226
- if ( strpos( $question, '%BLANK%' ) !== false ) {
1227
- $question = str_replace( '%BLANK%', $input_text, do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
1228
- }
1229
- // $question_title = apply_filters('the_content', $question);
1230
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
1231
- qsm_question_title_func( $question, '', $new_question_title, $id );
1232
- echo apply_filters( 'qmn_fill_blank_display_front', '', $id, $question, $answers );
1233
- }
1234
-
1235
- /**
1236
- * This function determines how the fill in the blank question is graded.
1237
- *
1238
- * @params $id The ID of the multiple choice question
1239
- * @params $question The question that is being edited.
1240
- * @params @answers The array that contains the answers to the question.
1241
- * @return $return_array Returns the graded question to the results page
1242
- * @since 4.4.0
1243
- */
1244
- function qmn_fill_blank_review( $id, $question, $answers ) {
1245
- global $mlwQuizMasterNext;
1246
- $match_answer = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'matchAnswer' );
1247
- $return_array = array(
1248
- 'points' => 0,
1249
- 'correct' => 'incorrect',
1250
- 'user_text' => '',
1251
- 'correct_text' => '',
1252
- 'user_compare_text' => '',
1253
- );
1254
- if ( strpos( $question, '%BLANK%' ) !== false || strpos( $question, '%blank%' ) !== false ) {
1255
- $return_array['question_text'] = str_replace( array( '%BLANK%', '%blank%' ), array( '__________', '__________' ), do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
1256
- }
1257
- $correct_text = $user_input = $user_text = array();
1258
-
1259
- if ( isset( $_POST[ 'question' . $id ] ) && ! empty( $_POST[ 'question' . $id ] ) ) {
1260
- $question_input = array_map( 'sanitize_textarea_field', wp_unslash( $_POST[ 'question' . $id ] ) );
1261
-
1262
- foreach ( $question_input as $input ) {
1263
- $decode_user_answer = strval( stripslashes( htmlspecialchars_decode( $input, ENT_QUOTES ) ) );
1264
- $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
1265
- $user_input[] = mb_strtoupper( $mlw_user_answer );
1266
- $user_text[] = $mlw_user_answer;
1267
- }
1268
- }
1269
-
1270
- $total_correct = $user_correct = 0;
1271
- if ( 'sequence' === $match_answer ) {
1272
- foreach ( $answers as $key => $answer ) {
1273
- $decode_user_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
1274
- $decode_user_text = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_text ) ) );
1275
-
1276
- if ( mb_strtoupper( $decode_user_text ) == $user_input[ $key ] ) {
1277
- $return_array['points'] += $answer[1];
1278
- $user_correct += 1;
1279
- }
1280
- $total_correct++;
1281
- $correct_text[] = $answers[ $key ][0];
1282
- }
1283
-
1284
- $return_array['correct_text'] = strval( htmlspecialchars_decode( implode( '.', $correct_text ), ENT_QUOTES ) );
1285
-
1286
- $return_array['user_text'] = implode( '.', $user_text );
1287
- $return_array['user_compare_text'] = implode( '=====', $user_text );
1288
-
1289
- if ( $total_correct == $user_correct ) {
1290
- $return_array['correct'] = 'correct';
1291
- }
1292
- } else {
1293
- $answers_array = array();
1294
- $correct = true;
1295
- foreach ( $answers as $answer ) {
1296
- $decode_user_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
1297
- $decode_user_text = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_text ) ) );
1298
- $answers_array[] = mb_strtoupper( $decode_user_text );
1299
- }
1300
- $total_user_input = sizeof( $user_input );
1301
- $total_option = sizeof( $answers );
1302
- if ( $total_user_input < $total_option ) {
1303
- foreach ( $user_input as $k => $input ) {
1304
- $key = array_search( $input, $answers_array, true );
1305
- if ( false !== $key ) {
1306
- $return_array['points'] += $answers[ $key ][1];
1307
- } else {
1308
- $correct = false;
1309
- }
1310
- $correct_text[] = $answers[ $key ][0];
1311
- }
1312
- } else {
1313
- foreach ( $answers_array as $k => $answer ) {
1314
- $key = array_search( $answer, $user_input, true );
1315
- if ( false !== $key ) {
1316
- $return_array['points'] += $answers[ $k ][1];
1317
- } else {
1318
- $correct = false;
1319
- }
1320
- $correct_text[] = $answers[ $k ][0];
1321
- }
1322
- }
1323
- if ( $correct ) {
1324
- $return_array['correct'] = 'correct';
1325
- }
1326
- $return_array['user_text'] = implode( '.', $user_text );
1327
- $return_array['correct_text'] = implode( '.', $correct_text );
1328
- $return_array['user_compare_text'] = implode( '=====', $user_text );
1329
- }
1330
-
1331
- /**
1332
- * Hook to filter answers array
1333
- */
1334
-
1335
- return apply_filters( 'qmn_fill_blank_review', $return_array, $answers );
1336
- }
1337
-
1338
- // Start polar question
1339
- add_action( 'plugins_loaded', 'qmn_question_type_polar' );
1340
-
1341
- /**
1342
- * This function registers the fill in the blank question type
1343
  *
1344
  * @return void
1345
  * @since 6.4.1
1346
  */
1347
  function qmn_question_type_polar() {
1348
- global $mlwQuizMasterNext;
1349
- $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Polar', 'quiz-master-next' ), 'qmn_polar_display', true, 'qmn_polar_review', null, null, 13 );
1350
- }
1351
-
1352
- /**
1353
- * This function displays the fill in the blank question
1354
- *
1355
- * @params $id The ID of the multiple choice question
1356
- * @params $question The question that is being edited.
1357
- * @params @answers The array that contains the answers to the question.
1358
- * @since 6.4.1
1359
- */
1360
- function qmn_polar_display( $id, $question, $answers ) {
1361
- global $mlwQuizMasterNext;
1362
- $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
1363
- $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
1364
- $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
1365
- $autofill_att = $autofill ? "autocomplete='off' " : '';
1366
- $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
1367
- $input_text = '';
1368
- $first_point = isset( $answers[0][1] ) ? intval( $answers[0][1] ) : 0;
1369
- $second_point = isset( $answers[1][1] ) ? intval( $answers[1][1] ) : 0;
1370
- $is_reverse = false;
1371
- $check_point = $second_point;
1372
- if ( $first_point > $second_point ) {
1373
- $is_reverse = true;
1374
- $check_point = $first_point;
1375
- }
1376
- $total_answer = count( $answers );
1377
- $id = esc_attr( intval( $id ) );
1378
- $answar1 = $first_point;
1379
- $answar2 = $second_point;
1380
- $slider_data_atts = '';
1381
- $slider_data_atts .= ' data-answer1=' . $answar1 . ' ';
1382
- $slider_data_atts .= ' data-answer2=' . $answar2 . ' ';
1383
- $slider_data_atts .= ' data-is_reverse=' . intval( $is_reverse ) . ' ';
1384
- $slider_data_atts .= ' data-is_required=' . $required . ' ';
1385
- if ( 0 == $required ) {
1386
- $mlw_require_class = 'mlwRequiredText';
1387
- } else {
1388
- $mlw_require_class = '';
1389
- }
1390
- $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
1391
- qsm_question_title_func( $question, '', $new_question_title, $id );
1392
-
1393
- ?>
1394
- <span class="mlw_qmn_question question-type-polar-s">
1395
- <div class='left-polar-title'> <?php echo esc_html( $answers[0][0] ); ?> </div>
1396
- <div class='slider-main-wrapper'>
1397
- <input type='hidden' class='qmn_polar <?php echo esc_attr( $mlw_require_class ); ?>' id='question<?php echo esc_attr( $id ); ?>' name='question<?php echo esc_attr( $id ); ?>' value=''/>
1398
- <div id="slider-<?php echo esc_attr( $id ); ?>" <?php echo esc_attr( $slider_data_atts ); ?> ></div>
1399
- </div>
1400
- <div class='right-polar-title'><?php echo esc_html( $answers[1][0] ); ?></div>
1401
- </span>
1402
- <?php
1403
-
1404
- }
1405
-
1406
- /**
1407
- * This function determines how the fill in the blank question is graded.
1408
- *
1409
- * @params $id The ID of the multiple choice question
1410
- * @params $question The question that is being edited.
1411
- * @params @answers The array that contains the answers to the question.
1412
- * @return $return_array Returns the graded question to the results page
1413
- * @since 6.4.1
1414
- */
1415
- function qmn_polar_review( $id, $question, $answers ) {
1416
- $return_array = array(
1417
- 'points' => 0,
1418
- 'correct' => 'incorrect',
1419
- 'user_text' => '',
1420
- 'correct_text' => '',
1421
- );
1422
- if ( strpos( $question, '%POLAR_SLIDER%' ) !== false || strpos( $question, '%polar_slider%' ) !== false ) {
1423
- $return_array['question_text'] = str_replace( array( '%POLAR_SLIDER%', '%polar_slider%' ), array( '__________', '__________' ), do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
1424
- }
1425
- if ( isset( $_POST[ 'question' . $id ] ) ) {
1426
- $decode_user_answer = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
1427
- $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
1428
- } else {
1429
- $mlw_user_answer = ' ';
1430
- }
1431
- $return_array['user_text'] = $mlw_user_answer;
1432
- $return_array['points'] = $mlw_user_answer;
1433
- foreach ( $answers as $answer ) {
1434
- $decode_correct_text = $answer[1];
1435
- $return_array['correct_text'] = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_correct_text ) ) );
1436
- if ( trim( $decode_correct_text ) == $return_array['user_text'] && isset( $answer[2] ) && 1 == $answer[2] ) {
1437
- $return_array['correct'] = 'correct';
1438
- break;
1439
- }
1440
- }
1441
- /**
1442
- * Hook to filter answers array
1443
- */
1444
- return apply_filters( 'qmn_polar_review', $return_array, $answers );
1445
- }
1446
-
1447
- function qsm_question_title_func( $question, $question_type = '', $new_question_title = '', $question_id = 0 ) {
1448
- // $question_title = apply_filters('the_content', $question);
1449
- $question_title = $question;
1450
- global $wp_embed, $mlwQuizMasterNext;
1451
- $question_title = $wp_embed->run_shortcode( $question_title );
1452
- $question_title = preg_replace( '/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $question_title );
1453
- $polar_extra_class = '';
1454
- if ( 'polar' === $question_type ) {
1455
- $polar_extra_class = 'question-type-polar-s';
1456
- }
1457
- $qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
1458
- $deselect_answer = '';
1459
- if ( isset( $qmn_quiz_options->enable_deselect_option ) && 1 == $qmn_quiz_options->enable_deselect_option && ( 'multiple_choice' === $question_type || 'horizontal_multiple_choice' === $question_type ) ) {
1460
- $deselect_answer = '<a href="#" class="qsm-deselect-answer">Deselect Answer</a>';
1461
- }
1462
-
1463
- if ( $question_id ) {
1464
- $featureImageID = $mlwQuizMasterNext->pluginHelper->get_question_setting( $question_id, 'featureImageID' );
1465
- if ( $featureImageID ) {
1466
- ?>
1467
- <div class="qsm-featured-image"><?php echo wp_get_attachment_image( $featureImageID, apply_filters( 'qsm_filter_feature_image_size', 'full', $question_id ) ); ?></div>
1468
- <?php
1469
- }
1470
- }
1471
- if ( '' !== $new_question_title ) {
1472
- ?>
1473
- <div class='mlw_qmn_new_question'><?php echo esc_html( htmlspecialchars_decode( $new_question_title, ENT_QUOTES ) ); ?> </div>
1474
- <?php
1475
- $polar_extra_class .= ' qsm_remove_bold';
1476
- }
1477
-
1478
- ?>
1479
- <div class='mlw_qmn_question <?php echo esc_attr( $polar_extra_class ); ?>' >
1480
- <?php echo do_shortcode( htmlspecialchars_decode( $question_title, ENT_QUOTES ) . $deselect_answer ); ?>
1481
- </div>
1482
- <?php
1483
- }
1484
- ?>
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
  }
5
+ //
6
+ include 'question-types/qsm-question-type-multiple-choice.php';
7
  add_action( 'plugins_loaded', 'qmn_question_type_multiple_choice' );
8
+ //
9
+ include 'question-types/qsm-question-type-multiple-choice-horizontal.php';
10
+ add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_choice' );
11
+ //
12
+ include 'question-types/qsm-question-type-multiple-response.php';
13
+ add_action( 'plugins_loaded', 'qmn_question_type_multiple_response' );
14
+ //
15
+ include 'question-types/qsm-question-type-multiple-response-horizontal.php';
16
+ add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_response' );
17
+ //
18
+ include 'question-types/qsm-question-type-dropdown.php';
19
+ add_action( 'plugins_loaded', 'qmn_question_type_drop_down' );
20
+ //
21
+ include 'question-types/qsm-question-type-fill-in-the-blanks.php';
22
+ add_action( 'plugins_loaded', 'qmn_question_type_fill_blank' );
23
+ //
24
+ include 'question-types/qsm-question-type-file-upload.php';
25
+ add_action( 'plugins_loaded', 'qmn_question_type_file_upload' );
26
+ //
27
+ include 'question-types/qsm-question-type-date.php';
28
+ add_action( 'plugins_loaded', 'qmn_question_type_date' );
29
+ //
30
+ include 'question-types/qsm-question-type-short-answer.php';
31
+ add_action( 'plugins_loaded', 'qmn_question_type_small_open' );
32
+ //
33
+ include 'question-types/qsm-question-type-paragraph.php';
34
+ add_action( 'plugins_loaded', 'qmn_question_type_large_open' );
35
+ //
36
+ include 'question-types/qsm-question-type-text-or-html.php';
37
+ add_action( 'plugins_loaded', 'qmn_question_type_text_block' );
38
+ //
39
+ include 'question-types/qsm-question-type-number.php';
40
+ add_action( 'plugins_loaded', 'qmn_question_type_number' );
41
+ //
42
+ include 'question-types/qsm-question-type-polar.php';
43
+ add_action( 'plugins_loaded', 'qmn_question_type_polar' );
44
+ //
45
+ include 'question-types/qsm-question-type-opt-in.php';
46
+ add_action( 'plugins_loaded', 'qmn_question_type_accept' );
47
+ //
48
+ include 'question-types/qsm-question-type-captcha.php';
49
+ add_action( 'plugins_loaded', 'qmn_question_type_captcha' );
50
+ //
51
+ include 'question-types/qsm-question-title.php';
52
+ //
53
+ include 'classes/question-types/class-question-review.php';
54
+ //
55
+ include 'classes/question-types/class-question-review-fill-in-blanks.php';
56
+ //
57
+ include 'classes/question-types/class-question-review-file-upload.php';
58
+ //
59
+ include 'classes/question-types/class-question-review-choice.php';
60
+ //
61
+ include 'classes/question-types/class-question-review-text.php';
62
  /**
63
  * Registers the multiple choice type
64
  *
66
  * @since 4.4.0
67
  */
68
  function qmn_question_type_multiple_choice() {
69
+ global $mlwQuizMasterNext;
70
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Vertical Multiple Choice', 'quiz-master-next' ), 'qmn_multiple_choice_display', true, 'qmn_multiple_choice_review', null, null, 0 );
71
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 0, 'input_field', 'radio' );
72
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 0, 'category', 'Choice' );
73
  }
 
 
74
  /**
75
  * Registers the file upload type
76
  *
78
  * @since 6.3.7
79
  */
80
  function qmn_question_type_file_upload() {
81
+ global $mlwQuizMasterNext;
82
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'File Upload', 'quiz-master-next' ), 'qmn_file_upload_display', true, 'qmn_file_upload_review', null, null, 11 );
83
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 11, 'input_field', 'attachment' );
84
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 11, 'category', 'Others' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  }
 
 
86
  /**
87
  * Registers the date type
88
  *
90
  * @since 6.3.7
91
  */
92
  function qmn_question_type_date() {
93
+ global $mlwQuizMasterNext;
94
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Date', 'quiz-master-next' ), 'qmn_date_display', true, 'qmn_date_review', null, null, 12 );
95
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 12, 'input_field', 'text' );
96
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 12, 'category', 'Number' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
 
 
 
98
  /**
99
  * This function registers the horizontal multiple choice type.
100
  *
102
  * @since 4.4.0
103
  */
104
  function qmn_question_type_horizontal_multiple_choice() {
105
+ global $mlwQuizMasterNext;
106
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Horizontal Multiple Choice', 'quiz-master-next' ), 'qmn_horizontal_multiple_choice_display', true, 'qmn_horizontal_multiple_choice_review', null, null, 1 );
107
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 1, 'input_field', 'radio' );
108
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 1, 'category', 'Choice' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  }
 
 
 
110
  /**
111
  * This function registers the drop down question type
112
  *
114
  * @since 4.4.0
115
  */
116
  function qmn_question_type_drop_down() {
117
+ global $mlwQuizMasterNext;
118
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Drop Down', 'quiz-master-next' ), 'qmn_drop_down_display', true, 'qmn_drop_down_review', null, null, 2 );
119
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 2, 'input_field', 'select' );
120
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 2, 'category', 'Choice' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  }
 
 
 
122
  /**
123
  * This function registers the small open question type
124
  *
126
  * @since 4.4.0
127
  */
128
  function qmn_question_type_small_open() {
129
+ global $mlwQuizMasterNext;
130
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Short Answer', 'quiz-master-next' ), 'qmn_small_open_display', true, 'qmn_small_open_review', null, null, 3 );
131
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 3, 'input_field', 'text' );
132
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 3, 'category', 'Text' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
 
 
 
134
  /**
135
  * This function registers the multiple response question type
136
  *
138
  * @since 4.4.0
139
  */
140
  function qmn_question_type_multiple_response() {
141
+ global $mlwQuizMasterNext;
142
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Multiple Response', 'quiz-master-next' ), 'qmn_multiple_response_display', true, 'qmn_multiple_response_review', null, null, 4 );
143
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 4, 'input_field', 'checkbox' );
144
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 4, 'category', 'Choice' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  }
 
 
 
146
  /**
147
  * This function registers the large open question type.
148
  *
149
  * @since 4.4.0
150
  */
151
  function qmn_question_type_large_open() {
152
+ global $mlwQuizMasterNext;
153
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Paragraph', 'quiz-master-next' ), 'qmn_large_open_display', true, 'qmn_large_open_review', null, null, 5 );
154
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 5, 'input_field', 'text_area' );
155
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 5, 'category', 'Text' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
 
 
 
157
  /**
158
  * This function registers the text block question type
159
  *
161
  * @since 4.4.0
162
  */
163
  function qmn_question_type_text_block() {
164
+ global $mlwQuizMasterNext;
165
+ $edit_args = array(
166
+ 'inputs' => array(
167
+ 'question',
168
+ ),
169
+ 'information' => '',
170
+ 'extra_inputs' => array(),
171
+ 'function' => '',
172
+ );
173
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Text/HTML Section', 'quiz-master-next' ), 'qmn_text_block_display', false, null, $edit_args, null, 6 );
174
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 6, 'input_field', 'NA' );
175
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 6, 'category', 'Others' );
 
 
 
 
 
 
 
 
 
 
 
176
  }
 
 
 
177
  /**
178
  * This function registers the number question type
179
  *
184
  * @since 4.4.0
185
  */
186
  function qmn_question_type_number() {
187
+ global $mlwQuizMasterNext;
188
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Number', 'quiz-master-next' ), 'qmn_number_display', true, 'qmn_number_review', null, null, 7 );
189
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 7, 'input_field', 'text' );
190
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 7, 'category', 'Number' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  }
 
 
 
192
  /**
193
  * This function registers the accept question type.
194
  *
196
  * @since 4.4.0
197
  */
198
  function qmn_question_type_accept() {
199
+ global $mlwQuizMasterNext;
200
+ $edit_args = array(
201
+ 'inputs' => array(
202
+ 'question',
203
+ 'required',
204
+ ),
205
+ 'information' => '',
206
+ 'extra_inputs' => array(),
207
+ 'function' => '',
208
+ );
209
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Opt-in', 'quiz-master-next' ), 'qmn_accept_display', false, null, $edit_args, null, 8 );
210
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 8, 'input_field', 'Checkbox' );
211
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 8, 'category', 'Choice' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  }
 
 
 
213
  /**
214
  * This function registers the captcha question
215
  *
216
  * @since 4.4.0
217
  */
218
  function qmn_question_type_captcha() {
219
+ global $mlwQuizMasterNext;
220
+ $edit_args = array(
221
+ 'inputs' => array(
222
+ 'question',
223
+ 'required',
224
+ ),
225
+ 'information' => '',
226
+ 'extra_inputs' => array(),
227
+ 'function' => '',
228
+ );
229
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Captcha', 'quiz-master-next' ), 'qmn_captcha_display', false, null, $edit_args, null, 9 );
230
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 9, 'input_field', 'NA' );
231
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 9, 'category', 'Others' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  }
 
 
 
233
  /**
234
  * This function registers the horizontal multiple response question
235
  *
237
  * @since 4.4.0
238
  */
239
  function qmn_question_type_horizontal_multiple_response() {
240
+ global $mlwQuizMasterNext;
241
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Horizontal Multiple Response', 'quiz-master-next' ), 'qmn_horizontal_multiple_response_display', true, 'qmn_horizontal_multiple_response_review', null, null, 10 );
242
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 10, 'input_field', 'checkbox' );
243
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 10, 'category', 'Choice' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  }
 
 
 
245
  /**
246
  * This function registers the fill in the blank question type
247
  *
249
  * @since 4.4.0
250
  */
251
  function qmn_question_type_fill_blank() {
252
+ global $mlwQuizMasterNext;
253
+ $edit_args = array(
254
+ 'inputs' => array(
255
+ 'question',
256
+ 'answer',
257
+ 'hint',
258
+ 'correct_info',
259
+ 'comments',
260
+ 'category',
261
+ 'required',
262
+ ),
263
+ 'information' => __( 'For fill in the blank types, use %BLANK% to represent where to put the text box in your text.', 'quiz-master-next' ),
264
+ 'extra_inputs' => array(),
265
+ 'function' => '',
266
+ );
267
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Fill In The Blank', 'quiz-master-next' ), 'qmn_fill_blank_display', true, 'qmn_fill_blank_review', $edit_args, null, 14 );
268
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 14, 'input_field', 'text' );
269
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 14, 'category', 'Others' );
270
+ }
271
+ /**
272
+ * This function registers the polar question type
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  *
274
  * @return void
275
  * @since 6.4.1
276
  */
277
  function qmn_question_type_polar() {
278
+ global $mlwQuizMasterNext;
279
+ $mlwQuizMasterNext->pluginHelper->register_question_type( __( 'Polar', 'quiz-master-next' ), 'qmn_polar_display', true, 'qmn_polar_review', null, null, 13 );
280
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 13, 'input_field', 'slider' );
281
+ $mlwQuizMasterNext->pluginHelper->set_question_type_meta( 13, 'category', 'Choice' );
282
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
php/question-types/qsm-question-title.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ function qsm_question_title_func( $question, $question_type = '', $new_question_title = '', $question_id = 0 ) {
7
+ $question_title = $question;
8
+ global $wp_embed, $mlwQuizMasterNext;
9
+ $question_title = $wp_embed->run_shortcode( $question_title );
10
+ $question_title = preg_replace( '/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $question_title );
11
+ $polar_extra_class = '';
12
+ if ( 'polar' === $question_type ) {
13
+ $polar_extra_class = 'question-type-polar-s';
14
+ }
15
+ $qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
16
+ $deselect_answer = '';
17
+ if ( isset( $qmn_quiz_options->enable_deselect_option ) && 1 == $qmn_quiz_options->enable_deselect_option && ( 'multiple_choice' === $question_type || 'horizontal_multiple_choice' === $question_type ) ) {
18
+ $deselect_answer = '<a href="#" class="qsm-deselect-answer">Deselect Answer</a>';
19
+ }
20
+
21
+ if ( $question_id ) {
22
+ $featureImageID = $mlwQuizMasterNext->pluginHelper->get_question_setting( $question_id, 'featureImageID' );
23
+ if ( $featureImageID ) {
24
+ ?>
25
+ <div class="qsm-featured-image"><?php echo wp_get_attachment_image( $featureImageID, apply_filters( 'qsm_filter_feature_image_size', 'full', $question_id ) ); ?></div>
26
+ <?php
27
+ }
28
+ }
29
+ if ( '' !== $new_question_title ) {
30
+ ?>
31
+ <div class='mlw_qmn_new_question'><?php echo esc_html( htmlspecialchars_decode( $new_question_title, ENT_QUOTES ) ); ?> </div>
32
+ <?php
33
+ $polar_extra_class .= ' qsm_remove_bold';
34
+ }
35
+
36
+ ?>
37
+ <div class='mlw_qmn_question <?php echo esc_attr( $polar_extra_class ); ?>' >
38
+ <?php echo do_shortcode( htmlspecialchars_decode( $question_title, ENT_QUOTES ) . $deselect_answer ); ?>
39
+ </div>
40
+ <?php
41
+ }
php/question-types/qsm-question-type-captcha.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+ /**
6
+ * This function displays the captcha question
7
+ *
8
+ * @params $id The ID of the multiple choice question
9
+ * @params $question The question that is being edited.
10
+ * @params @answers The array that contains the answers to the question.
11
+ *
12
+ * @since 4.4.0
13
+ */
14
+ function qmn_captcha_display( $id, $question, $answers ) {
15
+ global $mlwQuizMasterNext;
16
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
17
+ if ( 0 == $required ) {
18
+ $mlw_require_class = 'mlwRequiredCaptcha';
19
+ } else {
20
+ $mlw_require_class = '';
21
+ }
22
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
23
+ ?>
24
+ <span class="mlw_qmn_question">
25
+ <?php qsm_question_title_func( $question, '', $new_question_title, $id ); ?>
26
+ </span>
27
+ <div class="mlw_captchaWrap">
28
+ <canvas alt="" id="mlw_captcha" class="mlw_captcha" width="100" height="50"></canvas>
29
+ </div>
30
+ <input type="text" class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" id="mlw_captcha_text" name="mlw_user_captcha"/>
31
+ <input type="hidden" name="mlw_code_captcha" id="mlw_code_captcha" value="none" />
32
+ <?php
33
+ echo apply_filters( 'qmn_captcha_display_front', '', $id, $question, $answers );
34
+ }
php/question-types/qsm-question-type-date.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function shows the content of the date field
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 6.3.7
14
+ */
15
+ function qmn_date_display( $id, $question, $answers ) {
16
+ global $mlwQuizMasterNext;
17
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
18
+ if ( 0 == $required ) {
19
+ $mlw_require_class = 'mlwRequiredDate';
20
+ } else {
21
+ $mlw_require_class = '';
22
+ }
23
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
24
+ qsm_question_title_func( $question, '', $new_question_title, $id );
25
+ ?>
26
+ <input type="date" class="mlw_answer_date <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ); ?>" value="" />
27
+ <?php
28
+ echo apply_filters( 'qmn_date_display_front', '', $id, $question, $answers );
29
+ }
30
+
31
+ /**
32
+ * This function reviews the date type.
33
+ *
34
+ * @params $id The ID of the multiple choice question
35
+ * @params $question The question that is being edited.
36
+ * @params @answers The array that contains the answers to the question.
37
+ * @return $return_array Returns the graded question to the results page
38
+ * @since 6.3.7
39
+ */
40
+ function qmn_date_review( $id, $question, $answers ) {
41
+ $current_question = new QSM_Question_Review_Text( $id, $question, $answers );
42
+ $user_text_array = $current_question->get_user_answer();
43
+ $correct_text_array = $current_question->get_correct_answer();
44
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
45
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
46
+ $return_array['correct'] = $current_question->get_answer_status();
47
+ $return_array['points'] = $current_question->get_points();
48
+ $return_array['user_answer'] = $user_text_array;
49
+ $return_array['correct_answer'] = $correct_text_array ;
50
+ /**
51
+ * Hook to filter answers array
52
+ */
53
+ return apply_filters( 'qmn_date_review', $return_array, $answers );
54
+ }
php/question-types/qsm-question-type-dropdown.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function shows the content of the multiple choice question.
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+ function qmn_drop_down_display( $id, $question, $answers ) {
16
+ global $mlwQuizMasterNext;
17
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
18
+ if ( 0 == $required ) {
19
+ $require_class = 'qsmRequiredSelect';
20
+ } else {
21
+ $require_class = '';
22
+ }
23
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
24
+ qsm_question_title_func( $question, '', $new_question_title, $id );
25
+ ?>
26
+ <select class="qsm_select qsm_dropdown <?php echo esc_attr( $require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>">
27
+ <option disabled selected value><?php echo esc_html__( 'Please select your answer', 'quiz-master-next' ); ?></option>
28
+ <?php
29
+ if ( is_array( $answers ) ) {
30
+ $mlw_answer_total = 0;
31
+ foreach ( $answers as $answer_index => $answer ) {
32
+ $mlw_answer_total++;
33
+ if ( '' !== $answer[0] ) {
34
+ ?>
35
+ <option value="<?php echo esc_attr( $answer_index ); ?>"><?php echo esc_html( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ); ?></option>
36
+ <?php
37
+ }
38
+ }
39
+ }
40
+ ?>
41
+ </select>
42
+ <?php
43
+ echo apply_filters( 'qmn_drop_down_display_front', '', $id, $question, $answers );
44
+ }
45
+
46
+ /**
47
+ * This function determines how the question is graded
48
+ *
49
+ * @params $id The ID of the multiple choice question
50
+ * @params $question The question that is being edited.
51
+ * @params @answers The array that contains the answers to the question.
52
+ * @return $return_array Returns the graded question to the results page
53
+ * @since 4.4.0
54
+ */
55
+ function qmn_drop_down_review( $id, $question, $answers ) {
56
+ $current_question = new QSM_Question_Review_Choice( $id, $question, $answers );
57
+ $user_text_array = $current_question->get_user_answer();
58
+ $correct_text_array = $current_question->get_correct_answer();
59
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
60
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
61
+ $return_array['correct'] = $current_question->get_answer_status();
62
+ $return_array['points'] = $current_question->get_points();
63
+ $return_array['user_answer'] = $user_text_array;
64
+ $return_array['correct_answer'] = $correct_text_array ;
65
+ /**
66
+ * Hook to filter answers array
67
+ */
68
+ return apply_filters( 'qmn_drop_down_review', $return_array, $answers );
69
+ }
php/question-types/qsm-question-type-file-upload.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+ /**
6
+ * This function shows the content of the file upload
7
+ *
8
+ * @param $id The ID of the multiple choice question
9
+ * @param $question The question that is being edited.
10
+ * @param @answers The array that contains the answers to the question.
11
+ *
12
+ * @since 6.3.7
13
+ */
14
+ function qmn_file_upload_display( $id, $question, $answers ) {
15
+ global $mlwQuizMasterNext;
16
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
17
+ if ( 0 == $required ) {
18
+ $mlw_require_class = 'mlwRequiredFileUpload';
19
+ } else {
20
+ $mlw_require_class = '';
21
+ }
22
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
23
+ qsm_question_title_func( $question, '', $new_question_title, $id );
24
+ ?> <div></div><input type="file" class="mlw_answer_file_upload <?php echo esc_attr( $mlw_require_class ); ?>"/>
25
+ <div style="display: none;" class="loading-uploaded-file"><img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( get_site_url() . '/wp-includes/images/spinner-2x.gif' ); ?>"></div>
26
+ <div style="display: none;" class="remove-uploaded-file"><span class="dashicons dashicons-trash"></span></div>
27
+ <input class="mlw_file_upload_hidden_value" type="hidden" name="question<?php echo esc_attr( $id ); ?>" value="" />
28
+ <span style="display: none;" class='mlw-file-upload-error-msg'></span>
29
+ <input class="mlw_file_upload_hidden_path" type="hidden" value="" />
30
+ <?php
31
+ echo apply_filters( 'qmn_file_upload_display_front', '', $id, $question, $answers );
32
+ }
33
+
34
+ /**
35
+ * This function determines how the file upload will work.
36
+ *
37
+ * @params $id The ID of the multiple choice question
38
+ * @params $question The question that is being edited.
39
+ * @params @answers The array that contains the answers to the question.
40
+ * @return $return_array Returns the graded question to the results page
41
+ * @since 5.3.7
42
+ */
43
+ function qmn_file_upload_review( $id, $question, $answers ) {
44
+ $current_question = new QSM_Question_Review_File_Upload($id, $question, $answers);
45
+ $user_text_array = $current_question->get_user_answer();
46
+ $correct_text_array = $current_question->get_correct_answer();
47
+ $return_array['user_text'] = ! empty( $user_text_array ) ? '<a target="_blank" href="' . $user_text_array['url'] . '">' . __( 'Click here to view', 'quiz-master-next' ) . '</a>' : '' ;
48
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
49
+ $return_array['correct'] = $current_question->get_answer_status('url');
50
+ $return_array['points'] = $current_question->get_points();
51
+ $return_array['user_answer'] = $user_text_array;
52
+ $return_array['correct_answer'] = $correct_text_array ;
53
+ /**
54
+ * Hook to filter answers array
55
+ */
56
+ return apply_filters( 'qmn_file_upload_review', $return_array, $answers );
57
+ }
php/question-types/qsm-question-type-fill-in-the-blanks.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function displays the fill in the blank question
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ * @since 4.4.0
13
+ */
14
+ function qmn_fill_blank_display( $id, $question, $answers ) {
15
+ global $mlwQuizMasterNext;
16
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
17
+ $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
18
+ $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
19
+ $autofill_att = $autofill ? "autocomplete='off' " : '';
20
+ $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
21
+ if ( 0 == $required ) {
22
+ $mlw_require_class = 'mlwRequiredText';
23
+ } else {
24
+ $mlw_require_class = '';
25
+ }
26
+ $input_text = '<input ' . $autofill_att . $limit_text_att . " type='text' class='qmn_fill_blank $mlw_require_class' name='question" . $id . "[]' />";
27
+ if ( strpos( $question, '%BLANK%' ) !== false ) {
28
+ $question = str_replace( '%BLANK%', $input_text, do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
29
+ }
30
+ // $question_title = apply_filters('the_content', $question);
31
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
32
+ qsm_question_title_func( $question, '', $new_question_title, $id );
33
+ echo apply_filters( 'qmn_fill_blank_display_front', '', $id, $question, $answers );
34
+ }
35
+
36
+ /**
37
+ * This function determines how the fill in the blank question is graded.
38
+ *
39
+ * @params $id The ID of the multiple choice question
40
+ * @params $question The question that is being edited.
41
+ * @params @answers The array that contains the answers to the question.
42
+ * @return $return_array Returns the graded question to the results page
43
+ * @since 4.4.0
44
+ */
45
+ function qmn_fill_blank_review( $id, $question, $answers ) {
46
+ $current_question = new QSM_Question_Review_Fill_In_Blanks( $id, $question, $answers );
47
+ $user_text_array = $current_question->get_user_answer();
48
+ $correct_text_array = $current_question->get_correct_answer();
49
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
50
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
51
+ $return_array['correct'] = $current_question->get_answer_status();
52
+ $return_array['points'] = $current_question->get_points();
53
+ $return_array['user_compare_text'] = ! empty( $user_text_array ) ? implode( '=====', $user_text_array ) : '' ;
54
+ $return_array['user_answer'] = $user_text_array;
55
+ $return_array['correct_answer'] = $correct_text_array ;
56
+ if ( $current_question->get_question_text() ) {
57
+ $return_array['question_text'] = $current_question->get_question_text();
58
+ }
59
+ /**
60
+ * Hook to filter answers array
61
+ */
62
+ return apply_filters( 'qmn_fill_blank_review', $return_array, $answers );
63
+ }
php/question-types/qsm-question-type-multiple-choice-horizontal.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ *
8
+ *
9
+ *
10
+ */
11
+
12
+ /**
13
+ * This function shows the content of the horizontal multiple choice question.
14
+ *
15
+ * @params $id The ID of the multiple choice question
16
+ * @params $question The question that is being edited.
17
+ * @params @answers The array that contains the answers to the question.
18
+ *
19
+ * @since 4.4.0
20
+ */
21
+ function qmn_horizontal_multiple_choice_display( $id, $question, $answers ) {
22
+ global $mlwQuizMasterNext;
23
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
24
+ if ( 0 == $required ) {
25
+ $mlw_require_class = 'mlwRequiredRadio';
26
+ } else {
27
+ $mlw_require_class = '';
28
+ }
29
+ $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
30
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
31
+ qsm_question_title_func( $question, 'horizontal_multiple_choice', $new_question_title, $id );
32
+ ?>
33
+ <div class="qmn_radio_answers qmn_radio_horizontal_answers <?php echo esc_attr( $mlw_require_class ); ?>">
34
+ <?php
35
+ if ( is_array( $answers ) ) {
36
+ $mlw_answer_total = 0;
37
+ foreach ( $answers as $answer_index => $answer ) {
38
+ $mlw_answer_total++;
39
+ if ( '' !== $answer[0] ) {
40
+ $answer_class = apply_filters( 'qsm_answer_wrapper_class', '', $answer, $id );
41
+ ?>
42
+ <span class="mlw_horizontal_choice <?php echo esc_attr( $answer_class ); ?>">
43
+ <input type="radio" class="qmn_quiz_radio" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
44
+ <label for="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>">
45
+ <?php
46
+ if ( 'image' === $answerEditor ) {
47
+ ?>
48
+ <img alt="<?php echo esc_attr( $new_question_title ); ?>" src=" <?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
49
+ <?php
50
+ } else {
51
+ echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
52
+ }
53
+ ?>
54
+ </label>
55
+ <?php
56
+ echo apply_filters( 'qsm_multiple_choice_horizontal_display_loop', '', $id, $question, $answers );
57
+ ?>
58
+ </span>
59
+ <?php
60
+ }
61
+ }
62
+ echo apply_filters( 'qmn_horizontal_multiple_choice_question_display', '', $id, $question, $answers );
63
+ ?>
64
+ <input type="radio" style="display: none;" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ); ?>_none" checked="checked" value="" />
65
+ <?php
66
+ }
67
+ ?>
68
+ </div>
69
+ <?php
70
+ echo apply_filters( 'qmn_horizontal_multiple_choice_display_front', '', $id, $question, $answers );
71
+ }
72
+
73
+ /**
74
+ * This function determines how the question is graded.
75
+ *
76
+ * @params $id The ID of the multiple choice question
77
+ * @params $question The question that is being edited.
78
+ * @params @answers The array that contains the answers to the question.
79
+ * @return $return_array Returns the graded question to the results page
80
+ * @since 4.4.0
81
+ */
82
+ function qmn_horizontal_multiple_choice_review( $id, $question, $answers ) {
83
+ $current_question = new QSM_Question_Review_Choice( $id, $question, $answers );
84
+ $user_text_array = $current_question->get_user_answer( 'single_response' );
85
+ $correct_text_array = $current_question->get_correct_answer();
86
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
87
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
88
+ $return_array['correct'] = $current_question->get_answer_status( 'single_response' );
89
+ $return_array['points'] = $current_question->get_points();
90
+ $return_array['user_answer'] = $user_text_array;
91
+ $return_array['correct_answer'] = $correct_text_array ;
92
+ /**
93
+ * Hook to filter answers array
94
+ */
95
+ return apply_filters( 'qmn_horizontal_multiple_choice_review', $return_array, $answers );
96
+ }
php/question-types/qsm-question-type-multiple-choice.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function shows the content of the multiple choice question.
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+
16
+ function qmn_multiple_choice_display( $id, $question, $answers ) {
17
+ global $mlwQuizMasterNext;
18
+ $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
19
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
20
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
21
+ if ( 0 == $required ) {
22
+ $mlw_require_class = 'mlwRequiredRadio';
23
+ } else {
24
+ $mlw_require_class = '';
25
+ }
26
+ // $question_title = apply_filters('the_content', $question);
27
+ qsm_question_title_func( $question, 'multiple_choice', $new_question_title, $id );
28
+ ?>
29
+ <div class='qmn_radio_answers <?php echo esc_attr( $mlw_require_class ); ?>'>
30
+ <?php
31
+ if ( is_array( $answers ) ) {
32
+ $mlw_answer_total = 0;
33
+ foreach ( $answers as $answer_index => $answer ) {
34
+ $mlw_answer_total++;
35
+ if ( '' !== $answer[0] ) {
36
+ $answer_class = apply_filters( 'qsm_answer_wrapper_class', '', $answer, $id );
37
+ if ( 'rich' === $answerEditor ) {
38
+ ?>
39
+ <div class='qmn_mc_answer_wrap <?php echo esc_attr( $answer_class ); ?>' id='question<?php echo esc_attr( $id ); ?>-<?php echo esc_attr( $mlw_answer_total ); ?>'>
40
+ <?php
41
+ } elseif ( 'image' === $answerEditor ) {
42
+ ?>
43
+ <div class='qmn_mc_answer_wrap qmn_image_option <?php echo esc_attr( $answer_class ); ?>' id='question<?php echo esc_attr( $id ); ?>-<?php echo esc_attr( $mlw_answer_total ); ?>'>
44
+ <?php
45
+ } else {
46
+ ?>
47
+ <div class="qmn_mc_answer_wrap <?php echo esc_attr( $answer_class ); ?>" id="question<?php echo esc_attr( $id ); ?>-<?php echo esc_attr( $mlw_answer_total ); ?> ">
48
+ <?php
49
+ }
50
+ ?>
51
+ <input type='radio' class='qmn_quiz_radio' name="<?php echo esc_attr( 'question' . $id ); ?>" id="<?php echo esc_attr( 'question' . $id . '_' . $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
52
+ <label for="<?php echo esc_attr( 'question' . $id . '_' . $mlw_answer_total ); ?>">
53
+ <?php
54
+ if ( 'image' === $answerEditor ) {
55
+ ?>
56
+ <img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
57
+ <span class="qsm_image_caption">
58
+ <?php echo esc_html( trim( htmlspecialchars_decode( $answer[3], ENT_QUOTES ) ) ); ?>
59
+ </span>
60
+ <?php
61
+ } else {
62
+ echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
63
+ }
64
+ ?>
65
+ </label>
66
+ <?php
67
+ echo apply_filters( 'qsm_multiple_choice_display_loop', ' ', $id, $question, $answers );
68
+ ?>
69
+ </div>
70
+ <?php
71
+ }
72
+ }
73
+ ?>
74
+ <input type="radio" style="display: none;" name="<?php echo esc_attr( 'question' . $id ); ?>" id="<?php echo esc_attr( 'question' . $id . '_none' ); ?>" checked="checked" value="" />
75
+ <?php
76
+ }
77
+ ?>
78
+ </div>
79
+ <?php
80
+ echo apply_filters( 'qmn_multiple_choice_display_front', '', $id, $question, $answers );
81
+ }
82
+
83
+ /**
84
+ * This function determines how the multiple choice question is graded.
85
+ *
86
+ * @params $id The ID of the multiple choice question
87
+ * @params $question The question that is being edited.
88
+ * @params @answers The array that contains the answers to the question.
89
+ * @return $return_array Returns the graded question to the results page
90
+ * @since 4.4.0
91
+ */
92
+ function qmn_multiple_choice_review( $id, $question, $answers ) {
93
+ $current_question = new QSM_Question_Review_Choice( $id, $question, $answers );
94
+ $user_text_array = $current_question->get_user_answer();
95
+ $correct_text_array = $current_question->get_correct_answer();
96
+ $return_array['user_answer'] = $user_text_array;
97
+ $return_array['correct_answer'] = $correct_text_array ;
98
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
99
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
100
+ $return_array['correct'] = $current_question->get_answer_status();
101
+ $return_array['points'] = $current_question->get_points();
102
+ return apply_filters( 'qmn_multiple_choice_review', $return_array, $answers );
103
+ }
php/question-types/qsm-question-type-multiple-response-horizontal.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+ /**
6
+ * This function displays the content of the multiple response question type
7
+ *
8
+ * @params $id The ID of the multiple choice question
9
+ * @params $question The question that is being edited.
10
+ * @params @answers The array that contains the answers to the question.
11
+ *
12
+ * @since 4.4.0
13
+ */
14
+ function qmn_horizontal_multiple_response_display( $id, $question, $answers ) {
15
+ global $mlwQuizMasterNext;
16
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
17
+ if ( 0 == $required ) {
18
+ $mlw_require_class = 'mlwRequiredCheck';
19
+ } else {
20
+ $mlw_require_class = '';
21
+ }
22
+ $limit_multiple_response = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_multiple_response' );
23
+ $limit_mr_text = '';
24
+ if ( $limit_multiple_response > 0 ) {
25
+ $limit_mr_text = 'onchange="qsmCheckMR(this,' . $limit_multiple_response . ')"';
26
+ }
27
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
28
+ $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
29
+ qsm_question_title_func( $question, '', $new_question_title, $id );
30
+ ?>
31
+ <div class="qmn_check_answers qmn_multiple_horizontal_check <?php echo esc_attr( $mlw_require_class ); ?>">
32
+ <?php
33
+ if ( is_array( $answers ) ) {
34
+ $mlw_answer_total = 0;
35
+ foreach ( $answers as $answer_index => $answer ) {
36
+ $mlw_answer_total++;
37
+ if ( '' !== $answer[0] ) {
38
+ ?>
39
+ <span class="mlw_horizontal_multiple">
40
+ <input type="checkbox" <?php echo esc_attr( $limit_mr_text ); ?> name="question<?php echo esc_attr( $id ) .'[]' ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
41
+ <label for="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>">
42
+ <?php
43
+ if ( 'image' === $answerEditor ) {
44
+ ?>
45
+ <img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
46
+ <?php
47
+ } else {
48
+ echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
49
+ }
50
+ ?>
51
+ </label>
52
+ </span>
53
+ <?php
54
+ }
55
+ }
56
+ }
57
+ ?>
58
+ </div>
59
+ <?php
60
+ echo apply_filters( 'qmn_horizontal_multiple_response_display_front', '', $id, $question, $answers );
61
+ }
62
+
63
+ /**
64
+ * This function determines how the multiple response is graded.
65
+ *
66
+ * @params $id The ID of the multiple choice question
67
+ * @params $question The question that is being edited.
68
+ * @params @answers The array that contains the answers to the question.
69
+ * @return $return_array Returns the graded question to the Results page
70
+ * @since 4.4.0
71
+ */
72
+ function qmn_horizontal_multiple_response_review( $id, $question, $answers ) {
73
+ $current_question = new QSM_Question_Review_Choice( $id, $question, $answers );
74
+ $user_text_array = $current_question->get_user_answer();
75
+ $correct_text_array = $current_question->get_correct_answer();
76
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
77
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
78
+ $return_array['correct'] = $current_question->get_answer_status();
79
+ $return_array['points'] = $current_question->get_points();
80
+ $return_array['user_answer'] = $user_text_array;
81
+ $return_array['correct_answer'] = $correct_text_array ;
82
+ /**
83
+ * Hook to filter answers array
84
+ */
85
+ return apply_filters( 'qmn_horizontal_multiple_response_review', $return_array, $answers );
86
+ }
php/question-types/qsm-question-type-multiple-response.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function shows the content of the multiple response question
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+ function qmn_multiple_response_display( $id, $question, $answers ) {
16
+ $limit_mr_text = '';
17
+ global $mlwQuizMasterNext;
18
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
19
+ $limit_multiple_response = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_multiple_response' );
20
+ if ( $limit_multiple_response > 0 ) {
21
+ $limit_mr_text = 'onchange="qsmCheckMR(this,' . $limit_multiple_response . ')"';
22
+ }
23
+ if ( 0 == $required ) {
24
+ $mlw_require_class = 'mlwRequiredCheck';
25
+ } else {
26
+ $mlw_require_class = '';
27
+ }
28
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
29
+ $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
30
+ qsm_question_title_func( $question, '', $new_question_title, $id );
31
+ ?>
32
+ <div class="qmn_check_answers <?php echo esc_attr( $mlw_require_class ); ?>">
33
+ <?php
34
+ if ( is_array( $answers ) ) {
35
+ $mlw_answer_total = 0;
36
+ foreach ( $answers as $answer_index => $answer ) {
37
+ $mlw_answer_total++;
38
+ if ( '' !== $answer[0] ) {
39
+ ?>
40
+ <div class="qsm_check_answer">
41
+ <input type="checkbox" <?php echo esc_attr( $limit_mr_text ); ?> name="question<?php echo esc_attr( $id ) . '[]' ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
42
+ <label for="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>">
43
+ <?php
44
+ if ( 'image' === $answerEditor ) {
45
+ ?>
46
+ <img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
47
+ <?php
48
+ } else {
49
+ echo wp_kses_post( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ) );
50
+ }
51
+ ?>
52
+ </label>
53
+ </div>
54
+ <?php
55
+ }
56
+ }
57
+ }
58
+ ?>
59
+ </div>
60
+ <?php
61
+ echo apply_filters( 'qmn_multiple_response_display_front', '', $id, $question, $answers );
62
+ }
63
+
64
+ /**
65
+ * This function determines how the multiple response is graded,
66
+ *
67
+ * @params $id The ID of the multiple choice question
68
+ * @params $question The question that is being edited.
69
+ * @params @answers The array that contains the answers to the question.
70
+ * @return $return_array Returns the graded question to the results page
71
+ * @since 4.4.0
72
+ */
73
+ function qmn_multiple_response_review( $id, $question, $answers ) {
74
+ $current_question = new QSM_Question_Review_Choice( $id, $question, $answers );
75
+ $user_text_array = $current_question->get_user_answer();
76
+ $correct_text_array = $current_question->get_correct_answer();
77
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
78
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
79
+ $return_array['correct'] = $current_question->get_answer_status();
80
+ $return_array['points'] = $current_question->get_points();
81
+ $return_array['user_answer'] = $user_text_array;
82
+ $return_array['correct_answer'] = $correct_text_array ;
83
+ /**
84
+ * Hook to filter answers array
85
+ */
86
+ return apply_filters( 'qmn_multiple_response_review', $return_array, $answers );
87
+ }
php/question-types/qsm-question-type-number.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function shows the content of the multiple choice question.
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+ function qmn_number_display( $id, $question, $answers ) {
16
+ global $mlwQuizMasterNext;
17
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
18
+ $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
19
+ $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' oninput='javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);'" : '';
20
+ if ( 0 == $required ) {
21
+ $mlw_require_class = 'mlwRequiredNumber';
22
+ } else {
23
+ $mlw_require_class = '';
24
+ }
25
+ // $question_title = apply_filters('the_content', $question);
26
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
27
+ qsm_question_title_func( $question, '', $new_question_title, $id );
28
+ ?>
29
+ <input type="number" <?php echo esc_attr( $limit_text_att ); ?> class="mlw_answer_number <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" />
30
+ <?php
31
+ echo apply_filters( 'qmn_number_display_front', '', $id, $question, $answers );
32
+ }
33
+
34
+ /**
35
+ * This function determines how the number question type is graded.
36
+ *
37
+ * @params $id The ID of the multiple choice question
38
+ * @params $question The question that is being edited.
39
+ * @params @answers The array that contains the answers to the question.
40
+ * @return $return_array Returns the graded question to the results page
41
+ * @since 4.4.0
42
+ */
43
+ function qmn_number_review( $id, $question, $answers ) {
44
+ $current_question = new QSM_Question_Review_Text( $id, $question, $answers );
45
+ $user_text_array = $current_question->get_user_answer();
46
+ $correct_text_array = $current_question->get_correct_answer();
47
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
48
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
49
+ $return_array['correct'] = $current_question->get_answer_status();
50
+ $return_array['points'] = $current_question->get_points();
51
+ $return_array['user_answer'] = $user_text_array;
52
+ $return_array['correct_answer'] = $correct_text_array ;
53
+ /**
54
+ * Hook to filter answers array
55
+ */
56
+ return apply_filters( 'qmn_number_review', $return_array, $answers );
57
+ }
php/question-types/qsm-question-type-opt-in.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function displays the accept question
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+ function qmn_accept_display( $id, $question, $answers ) {
16
+ global $mlwQuizMasterNext;
17
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
18
+ if ( 0 == $required ) {
19
+ $mlw_require_class = 'mlwRequiredAccept';
20
+ } else {
21
+ $mlw_require_class = '';
22
+ }
23
+ ?>
24
+ <div class="qmn_accept_answers">
25
+ <input type="checkbox" id="mlwAcceptance" class="<?php echo esc_attr( $mlw_require_class ); ?>" />
26
+ <label for="mlwAcceptance"><span class="qmn_accept_text"><?php echo wp_kses_post( do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) ); ?></span></label>
27
+ </div>
28
+ <?php
29
+ echo apply_filters( 'qmn_accept_display_front', '', $id, $question, $answers );
30
+ }
php/question-types/qsm-question-type-paragraph.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function displays the content of the large open question.
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+ function qmn_large_open_display( $id, $question, $answers ) {
16
+ global $mlwQuizMasterNext;
17
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
18
+ $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
19
+ if ( 0 == $required ) {
20
+ $mlw_require_class = 'mlwRequiredText';
21
+ } else {
22
+ $mlw_require_class = '';
23
+ }
24
+ $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
25
+ // $question_title = apply_filters('the_content', $question);
26
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
27
+ qsm_question_title_func( $question, '', $new_question_title, $id );
28
+ ?>
29
+ <textarea class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" <?php echo esc_attr( $limit_text_att ); ?> cols="70" rows="5" name="question<?php echo esc_attr( $id ); ?>" /></textarea>
30
+ <?php
31
+ echo apply_filters( 'qmn_large_open_display_front', '', $id, $question, $answers );
32
+ }
33
+
34
+ /**
35
+ * This function determines how the large open question is graded
36
+ *
37
+ * @params $id The ID of the multiple choice question
38
+ * @params $question The question that is being edited.
39
+ * @params @answers The array that contains the answers to the question.
40
+ * @return $return_array Returns the graded question to the results page
41
+ * @since 4.4.0
42
+ */
43
+ function qmn_large_open_review( $id, $question, $answers ) {
44
+ $current_question = new QSM_Question_Review_Text( $id, $question, $answers );
45
+ $user_text_array = $current_question->get_user_answer();
46
+ $correct_text_array = $current_question->get_correct_answer();
47
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
48
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
49
+ $return_array['correct'] = $current_question->get_answer_status();
50
+ $return_array['points'] = $current_question->get_points();
51
+ $return_array['user_answer'] = $user_text_array;
52
+ $return_array['correct_answer'] = $correct_text_array ;
53
+ /**
54
+ * Hook to filter answers array
55
+ */
56
+ return apply_filters( 'qmn_large_open_review', $return_array, $answers );
57
+ }
php/question-types/qsm-question-type-polar.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function displays the fill in the blank question
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ * @since 6.4.1
13
+ */
14
+ function qmn_polar_display( $id, $question, $answers ) {
15
+ global $mlwQuizMasterNext;
16
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
17
+ $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
18
+ $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
19
+ $autofill_att = $autofill ? "autocomplete='off' " : '';
20
+ $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
21
+ $input_text = '';
22
+ $first_point = isset( $answers[0][1] ) ? intval( $answers[0][1] ) : 0;
23
+ $second_point = isset( $answers[1][1] ) ? intval( $answers[1][1] ) : 0;
24
+ $is_reverse = false;
25
+ $check_point = $second_point;
26
+ if ( $first_point > $second_point ) {
27
+ $is_reverse = true;
28
+ $check_point = $first_point;
29
+ }
30
+ $total_answer = count( $answers );
31
+ $id = esc_attr( intval( $id ) );
32
+ $answar1 = $first_point;
33
+ $answar2 = $second_point;
34
+ $slider_data_atts = '';
35
+ $slider_data_atts .= ' data-answer1=' . $answar1 . ' ';
36
+ $slider_data_atts .= ' data-answer2=' . $answar2 . ' ';
37
+ $slider_data_atts .= ' data-is_reverse=' . intval( $is_reverse ) . ' ';
38
+ $slider_data_atts .= ' data-is_required=' . $required . ' ';
39
+ if ( 0 == $required ) {
40
+ $mlw_require_class = 'mlwRequiredText';
41
+ } else {
42
+ $mlw_require_class = '';
43
+ }
44
+ qsm_question_title_func( $question, '', $new_question_title, $id );
45
+
46
+ ?>
47
+ <span class="mlw_qmn_question question-type-polar-s">
48
+ <div class='left-polar-title'> <?php echo esc_html( $answers[0][0] ); ?> </div>
49
+ <div class='slider-main-wrapper'>
50
+ <input type='hidden' class='qmn_polar <?php echo esc_attr( $mlw_require_class ); ?>' id='question<?php echo esc_attr( $id ); ?>' name='question<?php echo esc_attr( $id ); ?>' value=''/>
51
+ <div id="slider-<?php echo esc_attr( $id ); ?>" <?php echo esc_attr( $slider_data_atts ); ?> ></div>
52
+ </div>
53
+ <div class='right-polar-title'><?php echo esc_html( $answers[1][0] ); ?></div>
54
+ </span>
55
+ <?php
56
+
57
+ }
58
+
59
+ /**
60
+ * This function determines how the fill in the blank question is graded.
61
+ *
62
+ * @params $id The ID of the multiple choice question
63
+ * @params $question The question that is being edited.
64
+ * @params @answers The array that contains the answers to the question.
65
+ * @return $return_array Returns the graded question to the results page
66
+ * @since 6.4.1
67
+ */
68
+ function qmn_polar_review( $id, $question, $answers ) {
69
+ $return_array = array(
70
+ 'points' => 0,
71
+ 'correct' => 'incorrect',
72
+ 'user_text' => '',
73
+ 'correct_text' => '',
74
+ );
75
+ if ( strpos( $question, '%POLAR_SLIDER%' ) !== false || strpos( $question, '%polar_slider%' ) !== false ) {
76
+ $return_array['question_text'] = str_replace( array( '%POLAR_SLIDER%', '%polar_slider%' ), array( '__________', '__________' ), do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
77
+ }
78
+ if ( isset( $_POST[ 'question' . $id ] ) ) {
79
+ $decode_user_answer = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
80
+ $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
81
+ } else {
82
+ $mlw_user_answer = ' ';
83
+ }
84
+ $return_array['user_text'] = $mlw_user_answer;
85
+ $return_array['points'] = $mlw_user_answer;
86
+ foreach ( $answers as $answer ) {
87
+ $decode_correct_text = $answer[1];
88
+ $return_array['correct_text'] = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_correct_text ) ) );
89
+ if ( trim( $decode_correct_text ) == $return_array['user_text'] && isset( $answer[2] ) && 1 == $answer[2] ) {
90
+ $return_array['correct'] = 'correct';
91
+ break;
92
+ }
93
+ }
94
+ /**
95
+ * Hook to filter answers array
96
+ */
97
+ return apply_filters( 'qmn_polar_review', $return_array, $answers );
98
+ }
php/question-types/qsm-question-type-short-answer.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function shows the content of the small open answer question.
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+ function qmn_small_open_display( $id, $question, $answers ) {
16
+ global $mlwQuizMasterNext;
17
+ $required = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'required' );
18
+ $autofill = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'autofill' );
19
+ $limit_text = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_text' );
20
+ $autofill_att = $autofill ? "autocomplete='off' " : '';
21
+ $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
22
+ if ( 0 == $required ) {
23
+ $mlw_require_class = 'mlwRequiredText';
24
+ } else {
25
+ $mlw_require_class = '';
26
+ }
27
+ // $question_title = apply_filters('the_content', $question);
28
+ $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
29
+ qsm_question_title_func( $question, '', $new_question_title, $id );
30
+ ?>
31
+ <input <?php echo esc_attr( $autofill_att . $limit_text_att ); ?> type="text" class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" />
32
+ <?php
33
+ echo apply_filters( 'qmn_small_open_display_front', '', $id, $question, $answers );
34
+ }
35
+
36
+ /**
37
+ * This function reviews the small open answer.
38
+ *
39
+ * @params $id The ID of the multiple choice question
40
+ * @params $question The question that is being edited.
41
+ * @params @answers The array that contains the answers to the question.
42
+ * @return $return_array Returns the graded question to the results page
43
+ * @since 4.4.0
44
+ */
45
+ function qmn_small_open_review( $id, $question, $answers ) {
46
+ $current_question = new QSM_Question_Review_Text( $id, $question, $answers );
47
+ $user_text_array = $current_question->get_user_answer();
48
+ $correct_text_array = $current_question->get_correct_answer();
49
+ $return_array['user_text'] = ! empty( $user_text_array ) ? implode( '.', $user_text_array ) : '' ;
50
+ $return_array['correct_text'] = ! empty( $correct_text_array ) ? implode( '.', $correct_text_array ) : '';
51
+ $return_array['correct'] = $current_question->get_answer_status();
52
+ $return_array['points'] = $current_question->get_points();
53
+ $return_array['user_answer'] = $user_text_array;
54
+ $return_array['correct_answer'] = $correct_text_array ;
55
+ /**
56
+ * Hook to filter answers array
57
+ */
58
+ return apply_filters( 'qmn_small_open_review', $return_array, $answers );
59
+ }
php/question-types/qsm-question-type-text-or-html.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * This function displays the contents of the text block question type.
8
+ *
9
+ * @params $id The ID of the multiple choice question
10
+ * @params $question The question that is being edited.
11
+ * @params @answers The array that contains the answers to the question.
12
+ *
13
+ * @since 4.4.0
14
+ */
15
+ function qmn_text_block_display( $id, $question, $answers ) {
16
+ echo wp_kses_post( do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
17
+ }
php/template-variables.php CHANGED
@@ -537,7 +537,8 @@ function mlw_qmn_variable_timer_seconds( $content, $mlw_quiz_array ) {
537
  * @return string Returns the contents for the results page
538
  */
539
  function mlw_qmn_variable_date( $content, $results ) {
540
- $date = date_i18n( get_option( 'date_format' ), time() );
 
541
  $content = str_replace( '%CURRENT_DATE%', $date, $content );
542
  return $content;
543
  }
@@ -550,11 +551,28 @@ function mlw_qmn_variable_date( $content, $results ) {
550
  * @return string Returns the contents for the results page
551
  */
552
  function mlw_qmn_variable_date_taken( $content, $mlw_quiz_array ) {
 
 
553
  $date = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  if ( isset( $mlw_quiz_array['time_taken'] ) ) {
555
- $date = date_i18n( get_option( 'date_format' ), strtotime( $mlw_quiz_array['time_taken'] ) );
556
  }
557
  $content = str_replace( '%DATE_TAKEN%', $date, $content );
 
558
  return $content;
559
  }
560
 
@@ -569,10 +587,10 @@ function mlw_qmn_variable_date_taken( $content, $mlw_quiz_array ) {
569
  * @return string Returns the contents for the results page
570
  */
571
  function qmn_variable_category_points( $content, $mlw_quiz_array ) {
572
- global $mlwQuizMasterNext;
573
  $return_points = 0;
574
  while ( strpos( $content, '%CATEGORY_POINTS%' ) !== false || false !== strpos( $content, '%CATEGORY_POINTS_' ) ) {
575
- $return_points = 0;
 
576
  preg_match( '~%CATEGORY_POINTS%(.*?)%/CATEGORY_POINTS%~i', $content, $answer_text );
577
  if ( empty( $answer_text ) ) {
578
  $category_name = mlw_qmn_get_string_between( $content, '%CATEGORY_POINTS_', '%' );
@@ -580,25 +598,22 @@ function qmn_variable_category_points( $content, $mlw_quiz_array ) {
580
  $category_name = $answer_text[1];
581
  }
582
 
583
- $category_data = $mlwQuizMasterNext->migrationHelper->get_category_data( $category_name );
584
-
585
  foreach ( $mlw_quiz_array['question_answers_array'] as $answer ) {
586
- if ( $category_data['migrated'] ) {
587
- $length = 0;
588
- foreach ( $category_data['ids'] as $id ) {
589
- if ( in_array( $id, $answer['multicategories'], true ) ) {
590
- $length++;
 
591
  }
592
  }
593
- if ( sizeof( $category_data['ids'] ) == $length ) {
594
- $return_points += $answer['points'];
595
- }
596
- } else {
597
- if ( $answer['category'] == $category_name ) {
598
- $return_points += $answer['points'];
599
- }
600
  }
601
  }
 
 
 
 
 
602
  if ( empty( $answer_text ) ) {
603
  $content = str_replace( '%CATEGORY_POINTS_' . $category_name . '%', $return_points, $content );
604
  } else {
@@ -670,10 +685,10 @@ function qmn_variable_average_category_points( $content, $mlw_quiz_array ) {
670
  * @return string Returns the contents for the results page
671
  */
672
  function qmn_variable_category_score( $content, $mlw_quiz_array ) {
673
- global $mlwQuizMasterNext;
674
  $return_score = 0;
675
  $total_questions = 0;
676
  $amount_correct = 0;
 
677
  while ( strpos( $content, '%CATEGORY_SCORE%' ) !== false || false !== strpos( $content, '%CATEGORY_SCORE_' ) ) {
678
  $return_score = 0;
679
  $total_questions = 0;
@@ -683,29 +698,16 @@ function qmn_variable_category_score( $content, $mlw_quiz_array ) {
683
  $category_name = mlw_qmn_get_string_between( $content, '%CATEGORY_SCORE_', '%' );
684
  } else {
685
  $category_name = $answer_text[1];
686
- }
687
 
688
- $category_data = $mlwQuizMasterNext->migrationHelper->get_category_data( $category_name );
689
 
690
  foreach ( $mlw_quiz_array['question_answers_array'] as $answer ) {
691
- if ( $category_data['migrated'] ) {
692
- $length = 0;
693
- foreach ( $category_data['ids'] as $id ) {
694
- if ( in_array( $id, $answer['multicategories'], true ) ) {
695
- $length++;
696
- }
697
- }
698
- if ( sizeof( $category_data['ids'] ) == $length ) {
699
- $total_questions += 1;
700
- if ( 'correct' === $answer['correct'] ) {
701
- $amount_correct += 1;
702
- }
703
- }
704
- } else {
705
- if ( $answer['category'] == $category_name ) {
706
- $total_questions += 1;
707
- if ( 'correct' === $answer['correct'] ) {
708
- $amount_correct += 1;
709
  }
710
  }
711
  }
@@ -934,7 +936,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
934
  $question_answer_class = 'qmn_question_answer_correct';
935
  } else {
936
  if ( 'correct' === $answer['correct'] ) {
937
- $user_answer_class = 'qmn_user_correct_answer';
938
  $question_answer_class = 'qmn_question_answer_correct';
939
  } else {
940
  $user_answer_class = 'qmn_user_incorrect_answer';
@@ -967,7 +969,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
967
  $remove_border = false;
968
  $question_with_answer_text = '';
969
  $extra_border_bottom_class = 'qsm-add-border-bottom';
970
- $show_two_option_questions = array(
971
  3,
972
  12,
973
  5,
@@ -985,9 +987,9 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
985
  delete_post_meta( $answer['id'], 'qsm_random_quetion_answer' );
986
  }
987
  if ( $total_answers ) {
988
- if ( isset( $answer['question_type'] ) && in_array( intval( $answer['question_type'] ), $show_two_option_questions, true ) ) {
989
  $do_show_wrong = true;
990
- foreach ( $total_answers as $single_answer ) {
991
  $current_answer_zero = trim( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) );
992
 
993
  if ( 0 == $form_type && ( 0 == $quiz_system || 3 == $quiz_system ) ) {
@@ -1021,7 +1023,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1021
  }
1022
  }
1023
  } else {
1024
- $user_given_answer = '' === $answer[1] ? __( 'No answer provided', 'quiz-master-next' ) : $answer[1];
1025
  $question_with_answer_text .= '<span class="qsm-text-simple-option">' . htmlspecialchars_decode( $user_given_answer, ENT_QUOTES ) . '</span>';
1026
  }
1027
  }
@@ -1062,13 +1064,14 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1062
  } else {
1063
  $options = array();
1064
  foreach ( $total_answers as $key => $single_answer ) {
1065
- $options[] = mb_strtoupper( $single_answer[0] );
1066
  }
 
1067
  if ( sizeof( $new_array_user_answer ) < sizeof( $total_answers ) ) {
1068
  foreach ( $new_array_user_answer as $show_user_answer ) {
1069
  $key = array_search( mb_strtoupper( $show_user_answer ), $options, true );
1070
- if ( false != $key ) {
1071
- $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer">' . $show_user_answer . '</span>';
1072
  } else {
1073
  if ( '' === $show_user_answer ) {
1074
  $show_user_answer = 'No answer provided';
@@ -1097,23 +1100,19 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1097
  } else {
1098
  if ( 0 == $form_type && ( 0 == $quiz_system || 3 == $quiz_system ) ) {
1099
  if ( isset( $answer['question_type'] ) && ( 4 == $answer['question_type'] || 10 == $answer['question_type'] ) ) {
1100
- $user_selected_answer = htmlspecialchars_decode( $answer[1], ENT_QUOTES );
1101
- $new_array_user_answer = isset( $answer['user_compare_text'] ) ? explode( '=====', $answer['user_compare_text'] ) : array();
1102
- foreach ( $total_answers as $single_answer ) {
1103
- $current_answer_text = trim( stripslashes( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) ) );
1104
  $is_answer_correct = false;
1105
- if ( $new_array_user_answer ) {
1106
- foreach ( $new_array_user_answer as $new_array_value ) {
1107
- $new_array_value = trim( stripslashes( htmlspecialchars_decode( $new_array_value, ENT_QUOTES ) ) );
1108
- if ( $current_answer_text == $new_array_value ) {
1109
- $is_answer_correct = true;
1110
- break;
1111
- }
1112
- }
1113
  }
1114
-
1115
  $image_class = '';
1116
-
1117
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1118
  $show_user_answer = '<img src="' . htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) . '"/>';
1119
  $image_class = 'qmn_image_option';
@@ -1121,11 +1120,11 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1121
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1122
  $image_class = '';
1123
  }
1124
- if ( isset( $single_answer[2] ) && 1 == $single_answer[2] && $is_answer_correct ) {
1125
  $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer ' . $image_class . '">' . $show_user_answer . '</span>';
1126
- } elseif ( isset( $single_answer[2] ) && 1 == $single_answer[2] ) {
1127
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1128
- } elseif ( $is_answer_correct && 1 !== $single_answer[2] ) {
1129
  $question_with_answer_text .= '<span class="qsm-text-wrong-option ' . $image_class . '">' . $show_user_answer . '</span>';
1130
  } else {
1131
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
@@ -1136,27 +1135,19 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1136
  $questionid = $questions[ $answer['id'] ]['question_id'];
1137
  $question_with_answer_text .= qmn_polar_display_on_resultspage( $questionid, $questions, $total_answers, $answer );
1138
  } elseif ( in_array( $answer['question_type'], $use_custom_default_template, true ) ) {
1139
- $questionid = $answer['question_type'];
1140
- $question_with_answer_text .= apply_filters( 'qsm_result_page_custom_default_template', $questionid, $total_answers, $questions, $answer );
1141
  } else {
1142
- foreach ( $total_answers as $single_answer ) {
1143
- $single_answer_option = $single_answer[0];
1144
- if ( isset( $question_settings['answerEditor'] ) && 'rich' === $question_settings['answerEditor'] ) {
1145
- $single_answer_option = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1146
- $single_answer_option = htmlentities( $single_answer_option );
1147
- if ( strpos( $single_answer_option, '&lt;' ) !== false || strpos( $single_answer_option, '&quot;' ) !== false ) {
1148
- $single_answer_option = htmlspecialchars( $single_answer_option );
1149
- }
1150
- if ( strpos( $answer[1], '&lt;' ) !== false || strpos( $answer[1], '&quot;' ) !== false ) {
1151
- $answer_value = htmlentities( $answer[1] );
1152
- } else {
1153
- $answer_value = htmlspecialchars_decode( $answer[1], ENT_QUOTES );
1154
- $answer_value = htmlspecialchars_decode( $answer_value, ENT_QUOTES );
1155
- $answer_value = htmlentities( $answer_value );
1156
- $answer_value = htmlspecialchars( $answer_value );
1157
- }
1158
- } else {
1159
- $answer_value = $answer[1];
1160
  }
1161
  $image_class = '';
1162
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
@@ -1164,13 +1155,12 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1164
  $image_class = 'qmn_image_option';
1165
  } else {
1166
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1167
- $image_class = '';
1168
  }
1169
- if ( isset( $single_answer[2] ) && 1 == $single_answer[2] && $answer_value == $single_answer_option ) {
1170
  $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer ' . $image_class . '">' . $show_user_answer . '</span>';
1171
- } elseif ( isset( $single_answer[2] ) && 1 == $single_answer[2] ) {
1172
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1173
- } elseif ( $answer_value == $single_answer_option && 1 !== $single_answer[2] ) {
1174
  $question_with_answer_text .= '<span class="qsm-text-wrong-option ' . $image_class . '">' . $show_user_answer . '</span>';
1175
  } else {
1176
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
@@ -1180,8 +1170,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1180
  }
1181
  } else {
1182
  if ( isset( $answer['question_type'] ) && ( 4 == $answer['question_type'] || 10 == $answer['question_type'] ) ) {
1183
- $user_selected_answer = htmlspecialchars_decode( $answer[1], ENT_QUOTES );
1184
- foreach ( $total_answers as $single_answer ) {
1185
  $image_class = '';
1186
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1187
  $show_user_answer = '<img src="' . htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) . '"/>';
@@ -1190,7 +1179,9 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1190
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1191
  $image_class = '';
1192
  }
1193
- if ( false !== strpos( $user_selected_answer, $single_answer[0] ) ) {
 
 
1194
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1195
  } else {
1196
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
@@ -1199,13 +1190,13 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1199
  } else {
1200
  if ( 13 == $answer['question_type'] ) {
1201
  $questionid = $questions[ $answer['id'] ]['question_id'];
1202
-
1203
  $question_with_answer_text .= qmn_polar_display_on_resultspage( $questionid, $questions, $total_answers, $answer );
1204
  } elseif ( in_array( $answer['question_type'], $use_custom_default_template, true ) ) {
1205
- $questionid = $answer['question_type'];
1206
- $question_with_answer_text .= apply_filters( 'qsm_result_page_custom_default_template', $questionid, $total_answers, $questions, $answer );
 
1207
  } else {
1208
- foreach ( $total_answers as $single_answer ) {
1209
  $image_class = '';
1210
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1211
  $show_user_answer = '<img src="' . htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) . '"/>';
@@ -1214,7 +1205,9 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1214
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1215
  $image_class = '';
1216
  }
1217
- if ( htmlspecialchars_decode( $answer[1], ENT_QUOTES ) == $single_answer[0] ) {
 
 
1218
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1219
  } else {
1220
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
@@ -1249,8 +1242,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1249
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag" . trim( htmlspecialchars_decode( $answer[1], ENT_QUOTES ) ) . $close_span_with_br, $mlw_question_answer_display );
1250
  }
1251
  } elseif ( in_array( $answer['question_type'], $use_custom_user_answer_template, true ) ) {
1252
- $questionid = $answer['question_type'];
1253
- $qsm_user_ans = apply_filters( 'qsm_result_page_custom_user_answer_template', $questionid, $answer );
1254
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', $qsm_user_ans, $mlw_question_answer_display );
1255
  } else {
1256
  $user_answer_new = $answer[1];
@@ -1299,6 +1291,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1299
 
1300
  return $display;
1301
  }
 
1302
  function qsm_get_question_maximum_points( $question = array() ) {
1303
  $question_max_point = 0;
1304
  if ( ! empty( $question ) && isset( $question['answers'] ) ) {
537
  * @return string Returns the contents for the results page
538
  */
539
  function mlw_qmn_variable_date( $content, $results ) {
540
+ global $mlw_quiz_array;
541
+ $date = isset( $mlw_quiz_array['time_taken'] ) ? date_i18n( get_option( 'date_format' ), strtotime( $mlw_quiz_array['time_taken'] ) ) : '';
542
  $content = str_replace( '%CURRENT_DATE%', $date, $content );
543
  return $content;
544
  }
551
  * @return string Returns the contents for the results page
552
  */
553
  function mlw_qmn_variable_date_taken( $content, $mlw_quiz_array ) {
554
+ global $mlwQuizMasterNext;
555
+
556
  $date = '';
557
+ $quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
558
+ $qsm_quiz_settings = maybe_unserialize( $quiz_options->quiz_settings );
559
+ $qsm_quiz_options = maybe_unserialize( $qsm_quiz_settings['quiz_options'] );
560
+ $qsm_global_settings = get_option( 'qsm-quiz-settings' );
561
+
562
+ // check if preferred date format is set at quiz level or plugin level. Default to WP date format otherwise
563
+ if ( isset( $qsm_quiz_options['preferred_date_format'] ) ) {
564
+ $preferred_date_format = $qsm_quiz_options['preferred_date_format'];
565
+ } elseif ( isset( $qsm_global_settings['preferred_date_format'] ) ) {
566
+ $preferred_date_format = isset( $qsm_global_settings['preferred_date_format'] );
567
+ } else {
568
+ $preferred_date_format = get_option( 'date_format' );
569
+ }
570
+ // filter date format
571
  if ( isset( $mlw_quiz_array['time_taken'] ) ) {
572
+ $date = date_i18n( $preferred_date_format, strtotime( $mlw_quiz_array['time_taken'] ) );
573
  }
574
  $content = str_replace( '%DATE_TAKEN%', $date, $content );
575
+
576
  return $content;
577
  }
578
 
587
  * @return string Returns the contents for the results page
588
  */
589
  function qmn_variable_category_points( $content, $mlw_quiz_array ) {
 
590
  $return_points = 0;
591
  while ( strpos( $content, '%CATEGORY_POINTS%' ) !== false || false !== strpos( $content, '%CATEGORY_POINTS_' ) ) {
592
+ $total_questions = 0;
593
+ $return_points = 0;
594
  preg_match( '~%CATEGORY_POINTS%(.*?)%/CATEGORY_POINTS%~i', $content, $answer_text );
595
  if ( empty( $answer_text ) ) {
596
  $category_name = mlw_qmn_get_string_between( $content, '%CATEGORY_POINTS_', '%' );
598
  $category_name = $answer_text[1];
599
  }
600
 
 
 
601
  foreach ( $mlw_quiz_array['question_answers_array'] as $answer ) {
602
+ if ( is_array( $answer['multicategories'] ) ) {
603
+ foreach ( $answer['multicategories'] as $category ) {
604
+ $category_name_object = get_term_by( 'ID', $category, 'qsm_category' );
605
+ if ( $category_name_object->name == $category_name && '11' !== $answer['question_type'] ) {
606
+ $total_questions += 1;
607
+ $return_points += $answer['points'];
608
  }
609
  }
 
 
 
 
 
 
 
610
  }
611
  }
612
+ if ( 0 != $total_questions ) {
613
+ $return_points = strval( $return_points );
614
+ } else {
615
+ $return_points = 0;
616
+ }
617
  if ( empty( $answer_text ) ) {
618
  $content = str_replace( '%CATEGORY_POINTS_' . $category_name . '%', $return_points, $content );
619
  } else {
685
  * @return string Returns the contents for the results page
686
  */
687
  function qmn_variable_category_score( $content, $mlw_quiz_array ) {
 
688
  $return_score = 0;
689
  $total_questions = 0;
690
  $amount_correct = 0;
691
+
692
  while ( strpos( $content, '%CATEGORY_SCORE%' ) !== false || false !== strpos( $content, '%CATEGORY_SCORE_' ) ) {
693
  $return_score = 0;
694
  $total_questions = 0;
698
  $category_name = mlw_qmn_get_string_between( $content, '%CATEGORY_SCORE_', '%' );
699
  } else {
700
  $category_name = $answer_text[1];
 
701
 
702
+ }
703
 
704
  foreach ( $mlw_quiz_array['question_answers_array'] as $answer ) {
705
+ if ( is_array( $answer['multicategories'] ) ) {
706
+ foreach ( $answer['multicategories'] as $category ) {
707
+ $category_name_object = get_term_by( 'ID', $category, 'qsm_category' );
708
+ if ( $category_name_object->name == $category_name && '11' !== $answer['question_type'] ) {
709
+ $total_questions += 1;
710
+ $amount_correct += $answer['points'];
 
 
 
 
 
 
 
 
 
 
 
 
711
  }
712
  }
713
  }
936
  $question_answer_class = 'qmn_question_answer_correct';
937
  } else {
938
  if ( 'correct' === $answer['correct'] ) {
939
+ $user_answer_class = 'qmn_user_correct_answer qsm-text-correct-option qsm-text-user-correct-answer';
940
  $question_answer_class = 'qmn_question_answer_correct';
941
  } else {
942
  $user_answer_class = 'qmn_user_incorrect_answer';
969
  $remove_border = false;
970
  $question_with_answer_text = '';
971
  $extra_border_bottom_class = 'qsm-add-border-bottom';
972
+ $question_with_text_input = array(
973
  3,
974
  12,
975
  5,
987
  delete_post_meta( $answer['id'], 'qsm_random_quetion_answer' );
988
  }
989
  if ( $total_answers ) {
990
+ if ( isset( $answer['question_type'] ) && in_array( intval( $answer['question_type'] ), $question_with_text_input, true ) ) {
991
  $do_show_wrong = true;
992
+ foreach ( $total_answers as $single_answer_key => $single_answer ) {
993
  $current_answer_zero = trim( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) );
994
 
995
  if ( 0 == $form_type && ( 0 == $quiz_system || 3 == $quiz_system ) ) {
1023
  }
1024
  }
1025
  } else {
1026
+ $user_given_answer = '' === $answer[1] ? __( 'No answer provided', 'quiz-master-next' ) : $answer[1];
1027
  $question_with_answer_text .= '<span class="qsm-text-simple-option">' . htmlspecialchars_decode( $user_given_answer, ENT_QUOTES ) . '</span>';
1028
  }
1029
  }
1064
  } else {
1065
  $options = array();
1066
  foreach ( $total_answers as $key => $single_answer ) {
1067
+ $options[] = mb_strtoupper( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) );
1068
  }
1069
+
1070
  if ( sizeof( $new_array_user_answer ) < sizeof( $total_answers ) ) {
1071
  foreach ( $new_array_user_answer as $show_user_answer ) {
1072
  $key = array_search( mb_strtoupper( $show_user_answer ), $options, true );
1073
+ if ( false !== $key ) {
1074
+ $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer">' . htmlspecialchars_decode( $show_user_answer, ENT_QUOTES ) . '</span>';
1075
  } else {
1076
  if ( '' === $show_user_answer ) {
1077
  $show_user_answer = 'No answer provided';
1100
  } else {
1101
  if ( 0 == $form_type && ( 0 == $quiz_system || 3 == $quiz_system ) ) {
1102
  if ( isset( $answer['question_type'] ) && ( 4 == $answer['question_type'] || 10 == $answer['question_type'] ) ) {
1103
+ foreach ( $total_answers as $single_answer_key => $single_answer ) {
1104
+ $current_answer_key = $single_answer_key;
1105
+ $user_answer_keys = array_keys( $answer['user_answer'] );
1106
+ $correct_answer_keys = array_keys( $answer['correct_answer'] );
1107
  $is_answer_correct = false;
1108
+ $is_user_answer = false;
1109
+ if ( in_array( $current_answer_key, $correct_answer_keys, true ) ) {
1110
+ $is_answer_correct = true;
1111
+ }
1112
+ if ( in_array( $current_answer_key, $user_answer_keys, true) ) {
1113
+ $is_user_answer = true;
 
 
1114
  }
 
1115
  $image_class = '';
 
1116
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1117
  $show_user_answer = '<img src="' . htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) . '"/>';
1118
  $image_class = 'qmn_image_option';
1120
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1121
  $image_class = '';
1122
  }
1123
+ if ( $is_user_answer && $is_answer_correct ) {
1124
  $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer ' . $image_class . '">' . $show_user_answer . '</span>';
1125
+ } elseif ( ! $is_user_answer && $is_answer_correct ) {
1126
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1127
+ } elseif ( $is_user_answer && ! $is_answer_correct ) {
1128
  $question_with_answer_text .= '<span class="qsm-text-wrong-option ' . $image_class . '">' . $show_user_answer . '</span>';
1129
  } else {
1130
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
1135
  $questionid = $questions[ $answer['id'] ]['question_id'];
1136
  $question_with_answer_text .= qmn_polar_display_on_resultspage( $questionid, $questions, $total_answers, $answer );
1137
  } elseif ( in_array( $answer['question_type'], $use_custom_default_template, true ) ) {
1138
+ $question_with_answer_text .= apply_filters( 'qsm_result_page_custom_default_template', $total_answers, $questions, $answer );
 
1139
  } else {
1140
+ foreach ( $total_answers as $single_answer_key => $single_answer ) {
1141
+ $current_answer_key = $single_answer_key;
1142
+ $user_answer_keys = array_keys( $answer['user_answer'] );
1143
+ $correct_answer_keys = array_keys( $answer['correct_answer'] );
1144
+ $is_answer_correct = false;
1145
+ $is_user_answer = false;
1146
+ if ( in_array( $current_answer_key, $correct_answer_keys, true ) ) {
1147
+ $is_answer_correct = true;
1148
+ }
1149
+ if ( in_array( $current_answer_key, $user_answer_keys, true) ) {
1150
+ $is_user_answer = true;
 
 
 
 
 
 
 
1151
  }
1152
  $image_class = '';
1153
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1155
  $image_class = 'qmn_image_option';
1156
  } else {
1157
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
 
1158
  }
1159
+ if ( $is_user_answer && $is_answer_correct ) {
1160
  $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer ' . $image_class . '">' . $show_user_answer . '</span>';
1161
+ } elseif ( ! $is_user_answer && $is_answer_correct ) {
1162
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1163
+ } elseif ( $is_user_answer && ! $is_answer_correct ) {
1164
  $question_with_answer_text .= '<span class="qsm-text-wrong-option ' . $image_class . '">' . $show_user_answer . '</span>';
1165
  } else {
1166
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
1170
  }
1171
  } else {
1172
  if ( isset( $answer['question_type'] ) && ( 4 == $answer['question_type'] || 10 == $answer['question_type'] ) ) {
1173
+ foreach ( $total_answers as $single_answer_key => $single_answer ) {
 
1174
  $image_class = '';
1175
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1176
  $show_user_answer = '<img src="' . htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) . '"/>';
1179
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1180
  $image_class = '';
1181
  }
1182
+ $current_answer_key = $single_answer_key;
1183
+ $user_answer_keys = array_keys( $answer['user_answer'] );
1184
+ if ( in_array( $current_answer_key, $user_answer_keys , true ) ) {
1185
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1186
  } else {
1187
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
1190
  } else {
1191
  if ( 13 == $answer['question_type'] ) {
1192
  $questionid = $questions[ $answer['id'] ]['question_id'];
 
1193
  $question_with_answer_text .= qmn_polar_display_on_resultspage( $questionid, $questions, $total_answers, $answer );
1194
  } elseif ( in_array( $answer['question_type'], $use_custom_default_template, true ) ) {
1195
+ $questionid = $questions[ $answer['id'] ]['question_id'];
1196
+ $question_type = $answer['question_type'];
1197
+ $question_with_answer_text .= apply_filters( 'qsm_result_page_custom_default_template', $total_answers, $questions, $answer );
1198
  } else {
1199
+ foreach ( $total_answers as $single_answer_key => $single_answer ) {
1200
  $image_class = '';
1201
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1202
  $show_user_answer = '<img src="' . htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) . '"/>';
1205
  $show_user_answer = htmlspecialchars_decode( $single_answer[0], ENT_QUOTES );
1206
  $image_class = '';
1207
  }
1208
+ $current_answer_key = $single_answer_key;
1209
+ $user_answer_keys = array_keys( $answer['user_answer'] );
1210
+ if ( in_array( $current_answer_key, $user_answer_keys , true ) ) {
1211
  $question_with_answer_text .= '<span class="qsm-text-correct-option ' . $image_class . '">' . $show_user_answer . '</span>';
1212
  } else {
1213
  $question_with_answer_text .= '<span class="qsm-text-simple-option ' . $image_class . '">' . $show_user_answer . '</span>';
1242
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag" . trim( htmlspecialchars_decode( $answer[1], ENT_QUOTES ) ) . $close_span_with_br, $mlw_question_answer_display );
1243
  }
1244
  } elseif ( in_array( $answer['question_type'], $use_custom_user_answer_template, true ) ) {
1245
+ $qsm_user_ans = apply_filters( 'qsm_result_page_custom_user_answer_template', $questions, $answer );
 
1246
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', $qsm_user_ans, $mlw_question_answer_display );
1247
  } else {
1248
  $user_answer_new = $answer[1];
1291
 
1292
  return $display;
1293
  }
1294
+
1295
  function qsm_get_question_maximum_points( $question = array() ) {
1296
  $question_max_point = 0;
1297
  if ( ! empty( $question ) && isset( $question['answers'] ) ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: quiz, survey, lead, test, score, exam, questionnaire, question,wordpress q
4
  Requires at least: 4.9
5
  Tested up to: 5.8
6
  Requires PHP: 5.4
7
- Stable tag: 7.3.7
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -151,6 +151,20 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
151
  18. Database
152
 
153
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  = 7.3.7 (December 27, 2021) =
156
  * Bug: Fixed issues in fill in the blanks question type
@@ -644,3 +658,18 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
644
 
645
  = 6.2.1 =
646
  Upgrade to fix cut submit button on mobile issue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  Requires at least: 4.9
5
  Tested up to: 5.8
6
  Requires PHP: 5.4
7
+ Stable tag: 7.3.8
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
151
  18. Database
152
 
153
  == Changelog ==
154
+ = 7.3.8 (January 18, 2022) =
155
+ * Bug: Fixed issues while taking quiz with logic questions.
156
+ * Bug: Fixed issues with category selection on email page.
157
+ * Bug: Fixed the issues with category points and score template variables.
158
+ * Bug: Fixed issues when contact form is set to appears at end of the quiz.
159
+ * Bug: Fixed issues with multiple quiz shortcode on a same page.
160
+ * Bug: Fixed issues with number of questions per category and random questions logic.
161
+ * Bug: Fixed security issues.
162
+ * Bug: Fixed issues with date and current date format in template variable.
163
+ * Bug: Fixed issues with QSM Theme.
164
+ * Enhancement: Added option to edit quiz in admin bar.
165
+ * Enhancement: Added option to disable first page on quiz.
166
+ * Enhancement: Made UI improvements in QSM.
167
+ * Enhancement: Made improvements in answer matching logic.
168
 
169
  = 7.3.7 (December 27, 2021) =
170
  * Bug: Fixed issues in fill in the blanks question type
658
 
659
  = 6.2.1 =
660
  Upgrade to fix cut submit button on mobile issue
661
+
662
+ 🌐Our Plugins
663
+
664
+ If you like this plugin, consider exploring our other plugins:
665
+
666
+ ☰ [Responsive Menu](https://wordpress.org/plugins/responsive-menu/) - Best WordPress Menu Builder Plugin to create awesome and interactive mobile & desktop menus for WordPress websites.
667
+
668
+ 📙 [Projectopia](https://wordpress.org/plugins/projectopia-core/) - Project Management & Invoicing plugin for WordPress. Generate invoices, send quotes, generate leads, manage clients, provide support - all inside your WordPress website.
669
+
670
+ 📅 [Booking Ultra](https://wordpress.org/plugins/booking-ultra-pro/) - Appointment Booking plugin for WordPress - Show a quick form to accept bookings for your services with pre-set booking slots. Ideal for salons, medical professionals, lawyers, consultants, etc.
671
+
672
+ ⚡ [InstaWP](https://instawp.io/) - Launch a quick WordPress site with this sandbox service. Create New WordPress instance within a second.
673
+
674
+ 🔒 [Hide My WP](https://hidemywp.net/) - Hide your WordPress from bots, attackers & spammers. Hides all the known URLs, paths, plugins, themes which can reveal that you are using WP, also comes with an in-built firewall & trust network.
675
+
templates/qmn_primary.css CHANGED
@@ -201,7 +201,9 @@ label.inline .mlw_qmn_question,
201
  .quiz_section select {
202
  height: 38px;
203
  }
204
-
 
 
205
  .quiz_section select:hover,
206
  .quiz_section textarea:hover,
207
  .quiz_section input[type="text"]:hover,
201
  .quiz_section select {
202
  height: 38px;
203
  }
204
+ .quiz_section select.qsm_select.qsm_dropdown {
205
+ height: auto;
206
+ }
207
  .quiz_section select:hover,
208
  .quiz_section textarea:hover,
209
  .quiz_section input[type="text"]:hover,