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

Version Description

(December 27, 2021) = * Bug: Fixed issues in fill in the blanks question type * Bug: Fixed issues with category selection on result page * Bug: Fixed issues with deletion and duplication capabilities for non admin users * Bug: Fixed issue where url parameters are being translated * Bug: Fixed the issues with category points and score template variables * Feature: Added a feature to hide/show columns in admin results page * Enhancement: Introduced Page Name and Page URL columns to admin results table * Enhancement: Made UI improvements in polar question type slider * Enhancement: Made UI improvements in template variable popup * Enhancement: Made improvements in Audit Logs

Download this release

Release Info

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

Code changes from version 7.3.6 to 7.3.7

css/common.css CHANGED
@@ -74,6 +74,15 @@ body .quiz_section .qsm_contact_div .mlw_qmn_question{
74
  border-color: rgb(119, 113, 113);
75
  top: -7px;
76
  border-radius: 0px;
 
 
 
 
 
 
 
 
 
77
  }
78
  .qsm-deselect-answer{
79
  float: right;
@@ -343,4 +352,5 @@ footer.qsm-popup__footer button.qsm-popup-secondary-button:hover{
343
  }
344
  .qsm_quiz_processing_box .qsm_quiz_processing_message{
345
  margin: 10px 0;
346
- }
 
74
  border-color: rgb(119, 113, 113);
75
  top: -7px;
76
  border-radius: 0px;
77
+ text-decoration: none;
78
+ color: #fff !important;
79
+ display: flex;
80
+ justify-content: center;
81
+ }
82
+ .site .question-type-polar-s a.ui-state-focus:focus{
83
+ background: rgba(119, 113, 113, 1);
84
+ border-color: rgb(119, 113, 113, 1);
85
+ text-decoration: none;
86
  }
87
  .qsm-deselect-answer{
88
  float: right;
352
  }
353
  .qsm_quiz_processing_box .qsm_quiz_processing_message{
354
  margin: 10px 0;
355
+ }
356
+
css/qsm-admin.css CHANGED
@@ -2329,4 +2329,14 @@ td.scheduled_time_start {
2329
 
2330
  #result_page_fb_image {
2331
  width: 25em;
 
 
 
 
 
 
 
 
 
 
2332
  }
2329
 
2330
  #result_page_fb_image {
2331
  width: 25em;
2332
+ }
2333
+
2334
+ .audit_buttons{
2335
+ display: flex;
2336
+ align-items: center;
2337
+ justify-content: space-between;
2338
+ }
2339
+ input#question_search::-webkit-search-cancel-button {
2340
+ outline: none;
2341
+ appearance: none;
2342
  }
js/qsm-admin.js CHANGED
@@ -375,9 +375,9 @@ var QSMAdmin;
375
  }).open();
376
  });
377
 
378
- $(document).on('change', '.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]', function () {
379
- var value = $(this).val();
380
- if (value == '0' ) {
381
  $('.global_setting_system').parents('tr').show();
382
  $('.global_setting_score_roundoff').parents('tr').show();
383
  }else {
@@ -386,26 +386,26 @@ var QSMAdmin;
386
 
387
  }
388
  });
389
- $(document).on('change', '.global_setting_system input[name="qsm-quiz-settings[system]"]', function () {
390
- var value = $('input[name="qsm-quiz-settings[system]"]:checked').val();
391
- var value1 = $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').val();
392
- if (value != '1' && value1 == '0' ) {
393
  $('.global_setting_score_roundoff').parents('tr').show();
394
- }else {
395
- $('.global_setting_score_roundoff').parents('tr').hide();
396
  }
397
  });
398
  $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').trigger('change');
399
  $('.global_setting_system input[name="qsm-quiz-settings[system]"]').trigger('change');
400
 
401
  });
402
- $(document).on('change', '.global_setting_system input[name="qsm-quiz-settings[system]"]', function () {
403
- var value = $('input[name="qsm-quiz-settings[system]"]:checked').val();
404
- var value1 = $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').val();
405
- if (value != '1' && value1 == '0' ) {
406
  $('.global_setting_score_roundoff').parents('tr').show();
407
- }else {
408
- $('.global_setting_score_roundoff').parents('tr').hide();
409
  }
410
  });
411
  $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').trigger('change');
@@ -418,9 +418,90 @@ var QSMAdmin;
418
  deleteResults(qid, qname);
419
  });
420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  }(jQuery));
422
 
423
  // result page
 
 
 
 
 
 
 
 
 
424
  function deleteResults(id, quizName) {
425
  jQuery("#delete_dialog").dialog({
426
  autoOpen: false,
@@ -446,7 +527,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
446
  jQuery("div.mlw_qmn_themeBlockActive").toggleClass("mlw_qmn_themeBlockActive");
447
  jQuery("#mlw_qmn_theme_block_" + theme).toggleClass("mlw_qmn_themeBlockActive");
448
  }
449
-
450
  jQuery(document).ready(function() {
451
  jQuery('.quiz_style_tab').click(function(e) {
452
  e.preventDefault();
@@ -457,7 +538,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
457
  jQuery('#' + current_id).show();
458
  });
459
  });
460
-
461
  jQuery(document).ready(function() {
462
  jQuery(document).on('click', '.qsm-activate-theme', function() {
463
  jQuery(this).parents('.theme-wrapper').find('input[name=quiz_theme_id]').prop("checked", true);
@@ -465,7 +546,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
465
  jQuery(document).on('input', '.quiz_featured_image', function() {
466
  jQuery('.qsm_featured_image_preview').attr('src', jQuery(this).val());
467
  });
468
-
469
  jQuery(document).on('click', '.filter-links a', function() {
470
  let current_id = jQuery(this).attr('data-id');
471
  jQuery(this).parents('.filter-links').find('li a').each(function() {
@@ -481,11 +562,11 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
481
  });
482
  })
483
  });
484
-
485
  jQuery(document).ready(function () {
486
  jQuery(document).on('click', '.qsm-customize-color-settings', function (e) {
487
  e.preventDefault();
488
- MicroModal.show('qsm-theme-color-settings');
489
  if( jQuery('.my-color-field').length > 0 ){
490
  jQuery('.my-color-field').wpColorPicker();
491
  }
@@ -578,7 +659,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
578
  MicroModal.show('modal-1');
579
  },
580
  };
581
-
582
  QSMQuizzesSurveys.load();
583
 
584
  $('#new_quiz_button_two').on('click', function (event) {
@@ -668,7 +749,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
668
  $(document).on('click', '#the-list .qsm-action-link-reset', function (event) {
669
  event.preventDefault();
670
  QSMQuizzesSurveys.openResetPopup($(this).parents('.qsm-quiz-row').data('id'));
671
- });
672
  $('#reset-stats-button').on('click', function (event) {
673
  event.preventDefault();
674
  $('#reset_quiz_form').submit();
@@ -688,7 +769,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
688
  MicroModal.show('modal-bulk-delete');
689
  } else{
690
  $('#posts-filter').submit();
691
- }
692
  });
693
  $(document).on('click', '.qsm-list-shortcode-view', function (e) {
694
  e.preventDefault();
@@ -709,7 +790,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
709
  document.execCommand("copy");
710
  });
711
  $('#bulk-delete-quiz-button').on('click', function (event) {
712
- event.preventDefault();
713
  if($("#bult-delete-quiz-form input[name='qsm_delete_question_from_qb']").is(":checked")){
714
  $("<input>",{
715
  "type":"hidden",
@@ -723,7 +804,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
723
  "name": "qsm_delete_from_db",
724
  "value": "1"
725
  } ).appendTo("#posts-filter");
726
- }
727
  $('#posts-filter').submit();
728
  });
729
  }
@@ -743,7 +824,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
743
  event.preventDefault();
744
  $('#new-quiz-form').submit();
745
  });
746
-
747
  //Hide/show the wizard quiz options
748
  $(document).on('change', '#quiz_settings select', function () {
749
  var value = $(this).val();
@@ -753,7 +834,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
753
  jQuery(this).closest('.input-group').next('.input-group').hide();
754
  }
755
  });
756
-
757
  //Show the menus on widget click
758
  $(document).on('click', '.qsm-new_menu_tab_items li', function (e) {
759
  $('.qsm-new_menu_tab_items li').removeClass('active');
@@ -763,7 +844,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
763
  $('#' + id).show();
764
  e.preventDefault();
765
  });
766
-
767
  $(document).on('click', '.qsm-wizard-wrap', function (e) {
768
  $('.qsm-wizard-menu .qsm-wizard-wrap').removeClass('active');
769
  $(this).addClass('active');
@@ -849,23 +930,23 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
849
  $('#model-wizard #quiz_settings #disable_scroll_next_previous_click-1').prop('checked', true).parents('.input-group').show();
850
  }
851
  });
852
-
853
  $(document).on('mouseover', '#downloaded_theme .theme-wrapper, #browse_themes .theme-wrapper', function (e) {
854
  e.preventDefault();
855
  if (!$(this).hasClass('active')) {
856
  $(this).find('.theme-name').stop().fadeTo('slow', 1);
857
  }
858
  });
859
-
860
  $(document).on('mouseout', '#downloaded_theme .theme-wrapper, #browse_themes .theme-wrapper', function (e) {
861
  e.preventDefault();
862
  if (!$(this).hasClass('active')) {
863
  $(this).find('.theme-name').stop().fadeTo('slow', 0);
864
  }
865
  });
866
-
867
  $(document).find('#select_themes .theme-actions').remove();
868
-
869
  $(document).on('click', '#new_quiz_button', function () {
870
  $('#quiz_settings').find('.qsm-opt-desc').each(function () {
871
  if ($(this)) {
@@ -934,7 +1015,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
934
  $('.multiple-category-notice').show();
935
  }(jQuery));
936
 
937
- // QSM - Admin Stats Page
938
  (function ($) {
939
  if (jQuery('body').hasClass('qsm_page_qmn_stats')) {
940
  if (window.stats_graph instanceof Chart){
@@ -970,7 +1051,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
970
  (function ($) {
971
  if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
972
  if (window.location.href.indexOf('tab=contact') > 0 ){
973
-
974
  QSMContact = {
975
  load : function() {
976
  if($.isArray(qsmContactObject.contactForm) && qsmContactObject.contactForm.length > 0){
@@ -980,7 +1061,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
980
  }
981
  },
982
  addField : function( fieldArray ) {
983
- var new_label = fieldArray.label.replace(/"/g, "'");
984
  var contactField = $( '<div class="contact-form-field new">' +
985
  '<div class="contact-form-group">' +
986
  '<label class="contact-form-label">Field Type</label>' +
@@ -1033,7 +1114,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1033
  contactField.find( '.type-control option[value="date"]').prop( 'selected', true );
1034
  break;
1035
  default:
1036
-
1037
  }
1038
  switch ( fieldArray.use ) {
1039
  case 'name':
@@ -1049,7 +1130,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1049
  contactField.find( '.use-control option[value="phone"]').prop( 'selected', true );
1050
  break;
1051
  default:
1052
-
1053
  }
1054
  $( '.contact-form' ).append( contactField );
1055
  setTimeout( QSMContact.removeNew, 250 );
@@ -1104,7 +1185,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1104
  quiz_id : qsmContactObject.quizID,
1105
  nonce : qsmContactObject.saveNonce,
1106
  };
1107
-
1108
  jQuery.post( ajaxurl, data, function( response ) {
1109
  QSMContact.saved( JSON.parse( response ) );
1110
  });
@@ -1138,7 +1219,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1138
  }
1139
  };
1140
  $(function() {
1141
-
1142
  QSMContact.load();
1143
  if( $('.contact-form > .contact-form-field').length === 0 ){
1144
  $('.save-contact').hide();
@@ -1166,7 +1247,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1166
  cursor: 'move',
1167
  opacity: 60,
1168
  placeholder: "ui-state-highlight"
1169
- });
1170
  });
1171
  }
1172
  }
@@ -1193,7 +1274,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1193
  email_content = wp.editor.getContent( $( this ).find( '.email-template' ).attr( 'id' ) );
1194
  } else {
1195
  email_content = $( this ).find( '.email-template' ).val()
1196
- }
1197
  email = {
1198
  'conditions': [],
1199
  'to': $( this ).find( '.to-email' ).val(),
@@ -1221,12 +1302,12 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1221
  data: data,
1222
  headers: { 'X-WP-Nonce': qsmEmailsObject.nonce },
1223
  })
1224
- .done(function( results ) {
1225
  if ( results.status ) {
1226
  QSMAdmin.displayAlert( 'Emails were saved!', 'success' );
1227
  } else {
1228
  QSMAdmin.displayAlert( 'There was an error when saving the emails. Please try again.', 'error' );
1229
- }
1230
  })
1231
  .fail(QSMAdmin.displayjQueryError);
1232
  },
@@ -1261,8 +1342,8 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1261
  var template = wp.template( 'email' );
1262
  $( '#qsm_emails' ).append( template( { id: QSMAdminEmails.total, to: to, subject: subject, content: content, replyTo: replyTo } ) );
1263
  conditions.forEach( function( condition, i, conditions) {
1264
- QSMAdminEmails.addCondition(
1265
- $( '.qsm-email:last-child' ),
1266
  condition.category,
1267
  condition.criteria,
1268
  condition.operator,
@@ -1327,11 +1408,12 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1327
  /**
1328
  * QSM Question Tab
1329
  */
 
 
1330
  (function ($) {
1331
  if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1332
  if (window.location.href.indexOf('tab') == -1 ||window.location.href.indexOf('tab=questions')> 0 ){
1333
- var QSMQuestion;
1334
- var import_button;
1335
  $.QSMSanitize = function (input) {
1336
  return input.replace(/<(|\/|[^>\/bi]|\/[^>bi]|[^\/>][^>]+|\/[^>][^>]+)>/g, '');
1337
  };
@@ -1371,10 +1453,10 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1371
  */
1372
  countTotal: function () {
1373
  var total = 0;
1374
-
1375
  // Cycles through each page.
1376
  _.each(jQuery('.page'), function (page) {
1377
-
1378
  // If page is empty, continue to the next.
1379
  if (0 == jQuery(page).children('.question').length) {
1380
  return;
@@ -1566,10 +1648,10 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1566
  var pages = [];
1567
  var qpages = [];
1568
  var pageInfo = null;
1569
-
1570
  // Cycles through each page and add page + questions to pages variable
1571
  _.each(jQuery('.page'), function (page) {
1572
-
1573
  // If page is empty, do not add it.
1574
  if (0 == jQuery(page).children('.question').length) {
1575
  return;
@@ -1594,7 +1676,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1594
  quiz_id: qsmQuestionSettings.quizID,
1595
  nonce: qsmQuestionSettings.saveNonce,
1596
  };
1597
-
1598
  jQuery.ajax(ajaxurl, {
1599
  data: data,
1600
  method: 'POST',
@@ -1669,10 +1751,10 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1669
  } else {
1670
  questionName = new_question_title;
1671
  }
1672
-
1673
  if (questionName == '')
1674
  questionName = 'Your new question!';
1675
-
1676
  $('.page:nth-child(' + page + ')').append(template({
1677
  id: model.id,
1678
  category: model.get('category'),
@@ -1717,6 +1799,9 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1717
  var question_title = $('#question_title').val();
1718
  if (name == '' && question_title == '') {
1719
  alert('Enter Question title or description');
 
 
 
1720
  return false;
1721
  }
1722
  var advanced_option = {};
@@ -1749,7 +1834,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1749
  var featureImageSrc = $('.qsm-feature-image-src').val();
1750
  var answerType = $('#change-answer-editor').val();
1751
  var matchAnswer = $('#match-answer').val();
1752
-
1753
  var answers = [];
1754
  var $answers = jQuery('.answers-single');
1755
  _.each($answers, function (answer) {
@@ -1768,19 +1853,19 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1768
  answer = $answer.find('.answer-text').val().trim();
1769
  answer = $.QSMSanitize(answer);
1770
  }
1771
-
1772
  var points = $answer.find('.answer-points').val();
1773
  var correct = 0;
1774
  if ($answer.find('.answer-correct').prop('checked')) {
1775
  correct = 1;
1776
  }
1777
-
1778
  if (answerType == 'image') {
1779
  answers.push([answer, points, correct, caption]);
1780
  } else {
1781
  answers.push([answer, points, correct]);
1782
  }
1783
-
1784
  });
1785
  $('.questionElements .advanced-content > .qsm-row ').each(function () {
1786
  if ($(this).find('input[type="text"]').length > 0) {
@@ -1877,7 +1962,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1877
  quiz_system: qsmQuestionSettings.quiz_system
1878
  }));
1879
  }
1880
-
1881
  // show points field only for polar in survey and simple form
1882
  if (qsmQuestionSettings.form_type != 0) {
1883
  if (questionType == 13) {
@@ -1886,8 +1971,8 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1886
  $('#answers .answer-points').val('').hide();
1887
  }
1888
  }
1889
-
1890
-
1891
  if (answer[5] == 'rich' && qsmQuestionSettings.qsm_user_ve === 'true') {
1892
  var textarea_id = 'answer-' + answer[4] + '-' + answer[3];
1893
  wp.editor.remove(textarea_id);
@@ -1923,7 +2008,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1923
  var questionElements = $('#modal-1-content').html();
1924
  $('#modal-1-content').children().remove();
1925
  CurrentElement.parents('.question').after("<div style='display: none;' class='questionElements'>" + questionElements + "</div>");
1926
-
1927
  //Show question id on question edit screen
1928
  $('#qsm-question-id').text('ID: ' + questionID);
1929
  QSMQuestion.prepareCategories();
@@ -1948,7 +2033,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1948
  } else {
1949
  jQuery("#question-text").val(questionText);
1950
  }
1951
-
1952
  if ($('#wp-correct_answer_info-wrap').hasClass('html-active')) {
1953
  jQuery("#correct_answer_info").val(answerInfo);
1954
  } else if (CAI_editor) {
@@ -1956,7 +2041,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1956
  } else {
1957
  jQuery("#correct_answer_info").val(answerInfo);
1958
  }
1959
-
1960
  $('#answers').empty();
1961
  var answers = question.get('answers');
1962
  var answerEditor = question.get('answerEditor');
@@ -2021,20 +2106,20 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2021
  if (get_question_title === null || typeof get_question_title === "undefined") {
2022
  get_question_title = '';
2023
  }
2024
-
2025
  //Hide the question settings based on question type
2026
  $('.qsm_hide_for_other').hide();
2027
  if ($('.qsm_show_question_type_' + question.get('type')).length > 0) {
2028
  $('.qsm_show_question_type_' + question.get('type')).show();
2029
  }
2030
-
2031
  qsm_hide_show_question_desc(question.get('type'));
2032
  $('#hint').val(question.get('hint'));
2033
  $("#question_type").val(question.get('type'));
2034
  $("#comments").val(question.get('comments'));
2035
  //Changed checked logic based on new structure for required.
2036
  $("input#required[value='" + question.get('required') + "']").prop('checked', true);
2037
-
2038
  $("#hide_autofill").val(disableAutofill);
2039
  $("#limit_text").val(get_limit_text);
2040
  $("#limit_multiple_response").val(get_limit_mr);
@@ -2079,9 +2164,9 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2079
  //MicroModal.show( 'modal-1' );
2080
  $('.questions').sortable('disable');
2081
  $('.page').sortable('disable');
2082
-
2083
  QSMQuestion.sync_child_parent_category(questionID);
2084
-
2085
  jQuery(document).trigger('qsm_open_edit_popup', [questionID, CurrentElement]);
2086
  },
2087
  openEditPagePopup: function (pageID) {
@@ -2125,9 +2210,12 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2125
  jQuery(document).trigger('qsm_sync_child_parent_category', [checkbox, questionID]);
2126
  });
2127
  });
 
 
 
2128
  }
2129
  };
2130
-
2131
  $(function () {
2132
  QSMQuestion.pageCollection = Backbone.Collection.extend({
2133
  model: QSMQuestion.page
@@ -2142,30 +2230,30 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2142
  event.preventDefault();
2143
  QSMQuestion.addNewPage();
2144
  });
2145
-
2146
  $('.questions').on('click', '.new-question-button', function (event) {
2147
  event.preventDefault();
2148
  QSMQuestion.createQuestion($(this).parents('.page').index());
2149
  $('.save-page-button').trigger('click');
2150
  });
2151
-
2152
  $('.questions').on('click', '.add-question-bank-button', function (event) {
2153
  event.preventDefault();
2154
  QSMQuestion.openQuestionBank($(this).parents('.page').index());
2155
  });
2156
-
2157
  //Show more question on load more
2158
  $(document).on('click', '.qb-load-more-question', function (event) {
2159
  event.preventDefault();
2160
  QSMQuestion.loadQuestionBank();
2161
  });
2162
-
2163
  //Show category related question
2164
  $(document).on('change', '#question-bank-cat', function (event) {
2165
  event.preventDefault();
2166
  QSMQuestion.loadQuestionBank('change');
2167
  });
2168
-
2169
  $('.questions').on('click', '.edit-question-button', function (event) {
2170
  event.preventDefault();
2171
  $('.qsm-category-filter').trigger('keyup');
@@ -2175,7 +2263,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2175
  event.preventDefault();
2176
  QSMQuestion.openEditPagePopup($(this).parents('.page').data('page-id'));
2177
  });
2178
-
2179
  $(document).on('click', '.questions .duplicate-question-button', function (event) {
2180
  event.preventDefault();
2181
  QSMQuestion.duplicateQuestion($(this).parents('.question').data('question-id'));
@@ -2210,7 +2298,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2210
  $('.save-page-button').trigger('click');
2211
  MicroModal.close('modal-7');
2212
  });
2213
-
2214
  // unlink question from a particular quiz.
2215
  $('#unlink-question-button').click(function (event) {
2216
  event.preventDefault();
@@ -2220,7 +2308,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2220
  $('.save-page-button').trigger('click');
2221
  MicroModal.close('modal-7');
2222
  });
2223
-
2224
  $('.questions').on('click', '.delete-page-button', function (event) {
2225
  event.preventDefault();
2226
  if (confirm('Are you sure?')) {
@@ -2263,13 +2351,13 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2263
  return false;
2264
  }
2265
  }
2266
-
2267
-
2268
  }
2269
  $('#save-edit-question-spinner').addClass('is-active');
2270
  var model_html = $('#modal-1-content').html();
2271
  $('#modal-1-content').children().remove();
2272
-
2273
  QSMQuestion.saveQuestion($(this).parents('.questionElements').children('#edit_question_id').val(), $(this));
2274
  $('.save-page-button').trigger('click');
2275
  $('#modal-1-content').html(model_html);
@@ -2286,7 +2374,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2286
  var answer = ['', '', 0, answer_length + 1, question_id, answerType];
2287
  QSMQuestion.addNewAnswer(answer, 0);
2288
  });
2289
-
2290
  $('.qsm-popup-bank').on('click', '.import-button', function (event) {
2291
  event.preventDefault();
2292
  $(this).text('').text('Adding Question');
@@ -2294,7 +2382,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2294
  QSMQuestion.addQuestionFromQuestionBank($(this).parents('.question-bank-question').data('question-id'));
2295
  $('.import-button').addClass('disable_import');
2296
  });
2297
-
2298
  //Click on selected question button.
2299
  $('.qsm-popup-bank').on('click', '#qsm-import-selected-question', function (event) {
2300
  var $total_selction = $('#question-bank').find('[name="qsm-question-checkbox[]"]:checked').length;
@@ -2346,12 +2434,12 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2346
  }
2347
  }
2348
  });
2349
-
2350
  //Select all button.
2351
  $(document).on('change', '#qsm_select_all_question', function (event) {
2352
  $('.qsm-question-checkbox').prop('checked', jQuery('#qsm_select_all_question').prop('checked'));
2353
  });
2354
-
2355
  $('.save-page-button').on('click', function (event) {
2356
  event.preventDefault();
2357
  $('#save-edit-quiz-pages').addClass('is-active');
@@ -2373,7 +2461,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2373
  MicroModal.close('modal-page-1');
2374
  }
2375
  });
2376
-
2377
  $(document).on('change', '#change-answer-editor', function (event) {
2378
  var newVal = $(this).val();
2379
  if (confirm('All answer will be reset, Do you want to still continue?')) {
@@ -2387,7 +2475,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2387
  return false;
2388
  }
2389
  });
2390
-
2391
  // Adds event handlers for searching questions
2392
  $('#question_search').on('keyup', function () {
2393
  $('.question').each(function () {
@@ -2395,6 +2483,8 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2395
  $(this).hide();
2396
  } else {
2397
  $(this).show();
 
 
2398
  }
2399
  });
2400
  $('.page').each(function () {
@@ -2409,14 +2499,14 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2409
  $('.question').show();
2410
  }
2411
  });
2412
-
2413
  qsm_init_sortable();
2414
-
2415
  if (qsmQuestionSettings.qsm_user_ve === 'true') {
2416
  QSMQuestion.prepareEditor();
2417
  }
2418
  QSMQuestion.loadQuestions();
2419
-
2420
  /**
2421
  * Hide/show advanced option
2422
  */
@@ -2430,17 +2520,22 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2430
  }
2431
  });
2432
  });
2433
-
2434
  //Hide the question settings based on question type
2435
- $(document).on('change', '#question_type', function () {
2436
- var question_val = $(this).val();
 
 
 
 
 
2437
  if (6 == question_val) {
2438
  var question_description = wp.editor.getContent('question-text');
2439
  if (question_description == 'Add description here!') {
2440
  tinyMCE.get('question-text').setContent('');
2441
  }
2442
  }
2443
-
2444
  // show points field only for polar in survey and simple form
2445
  if (qsmQuestionSettings.form_type != 0) {
2446
  if (13 == question_val) {
@@ -2455,7 +2550,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2455
  }
2456
  qsm_hide_show_question_desc(question_val);
2457
  });
2458
-
2459
  //Add new category
2460
  $(document).on('click', '#qsm-category-add-toggle', function () {
2461
  if ($('#qsm-category-add').is(":visible")) {
@@ -2466,7 +2561,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2466
  $('#qsm-category-add').slideDown('slow');
2467
  }
2468
  });
2469
-
2470
  //Hide/show quesion description
2471
  $(document).on('click', '.qsm-show-question-desc-box', function (e) {
2472
  e.preventDefault();
@@ -2488,7 +2583,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2488
  $(this).next('.qsm-row').slideDown();
2489
  }
2490
  });
2491
-
2492
  //Open file upload on feature image
2493
  $('body').on('click', '.qsm-feature-image-upl', function (e) {
2494
  e.preventDefault();
@@ -2511,7 +2606,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2511
  button.next().next().next('.qsm-feature-image-src').val(attachment.url);
2512
  }).open();
2513
  });
2514
-
2515
  // on remove button click
2516
  $('body').on('click', '.qsm-feature-image-rmv', function (e) {
2517
  e.preventDefault();
@@ -2520,7 +2615,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2520
  button.next().next().val(''); // emptying the hidden field
2521
  button.hide().prev().html('Upload image');
2522
  });
2523
-
2524
  //Hide/show correct answer info
2525
  $(document).on('click', '.qsm-show-correct-info-box', function (e) {
2526
  e.preventDefault();
@@ -2537,14 +2632,14 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2537
  //create a new html document (doesn't execute script tags in child elements)
2538
  var doc = document.implementation.createHTMLDocument("");
2539
  var element = doc.createElement('div');
2540
-
2541
  function getText(str) {
2542
  element.innerHTML = str;
2543
  str = element.textContent;
2544
  element.textContent = '';
2545
  return str;
2546
  }
2547
-
2548
  function decodeHTMLEntities(str) {
2549
  if (str && typeof str === 'string') {
2550
  var x = getText(str);
@@ -2557,14 +2652,14 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2557
  }
2558
  return decodeHTMLEntities;
2559
  })();
2560
-
2561
  function qsm_hide_show_question_desc(question_type) {
2562
  $('.question-type-description').hide();
2563
  if ($('#question_type_' + question_type + '_description').length > 0) {
2564
  $('#question_type_' + question_type + '_description').show();
2565
  }
2566
  }
2567
-
2568
  function qsm_init_sortable() {
2569
  $('.questions').sortable({
2570
  opacity: 70,
@@ -2599,7 +2694,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2599
  }
2600
  });
2601
  }
2602
-
2603
  function qsmRandomID(length) {
2604
  var result = '';
2605
  var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@@ -2629,10 +2724,10 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2629
  $(this).hide();
2630
  }
2631
  });
2632
-
2633
  }
2634
  });
2635
-
2636
  $(document).on('click', '.add-multiple-category', function (e) {
2637
  e.preventDefault();
2638
  MicroModal.show('modal-9', {
@@ -2643,7 +2738,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2643
  }
2644
  });
2645
  });
2646
-
2647
  $(document).on('click', '#save-multi-category-button', function (e) {
2648
  e.preventDefault();
2649
  duplicate = false;
@@ -2660,7 +2755,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2660
  return false;
2661
  }
2662
  });
2663
-
2664
  if (!duplicate) {
2665
  var new_category_data = {
2666
  action: 'save_new_category',
@@ -2746,12 +2841,12 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2746
  data: data,
2747
  headers: { 'X-WP-Nonce': qsmResultsObject.nonce },
2748
  })
2749
- .done(function( results ) {
2750
  if ( results.status ) {
2751
  QSMAdmin.displayAlert( 'Results pages were saved!', 'success' );
2752
  } else {
2753
  QSMAdmin.displayAlert( 'There was an error when saving the results pages. Please try again.', 'error' );
2754
- }
2755
  })
2756
  .fail(QSMAdmin.displayjQueryError);
2757
  },
@@ -2787,7 +2882,7 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2787
  var template = wp.template( 'results-page' );
2788
  $( '#results-pages' ).append( template( { id: QSMAdminResults.total, page: page, redirect: redirect } ) );
2789
  conditions.forEach( function( condition, i, conditions) {
2790
- QSMAdminResults.addCondition(
2791
  $('.results-page:last-child'),
2792
  condition.category,
2793
  condition.criteria,
@@ -2819,14 +2914,14 @@ if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
2819
  };
2820
  $(function() {
2821
  QSMAdminResults.loadResults();
2822
-
2823
  $( '.add-new-page' ).on( 'click', function( event ) {
2824
  event.preventDefault();
2825
  QSMAdminResults.newResultsPage();
2826
  });
2827
  $( '.save-pages' ).on( 'click', function( event ) {
2828
- event.preventDefault();
2829
- QSMAdminResults.saveResults();
2830
  });
2831
  $( '#results-pages' ).on( 'click', '.new-condition', function( event ) {
2832
  event.preventDefault();
375
  }).open();
376
  });
377
 
378
+ $(document).on('change', '.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]', function () {
379
+ var value = $(this).val();
380
+ if (value == '0' ) {
381
  $('.global_setting_system').parents('tr').show();
382
  $('.global_setting_score_roundoff').parents('tr').show();
383
  }else {
386
 
387
  }
388
  });
389
+ $(document).on('change', '.global_setting_system input[name="qsm-quiz-settings[system]"]', function () {
390
+ var value = $('input[name="qsm-quiz-settings[system]"]:checked').val();
391
+ var value1 = $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').val();
392
+ if (value != '1' && value1 == '0' ) {
393
  $('.global_setting_score_roundoff').parents('tr').show();
394
+ }else {
395
+ $('.global_setting_score_roundoff').parents('tr').hide();
396
  }
397
  });
398
  $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').trigger('change');
399
  $('.global_setting_system input[name="qsm-quiz-settings[system]"]').trigger('change');
400
 
401
  });
402
+ $(document).on('change', '.global_setting_system input[name="qsm-quiz-settings[system]"]', function () {
403
+ var value = $('input[name="qsm-quiz-settings[system]"]:checked').val();
404
+ var value1 = $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').val();
405
+ if (value != '1' && value1 == '0' ) {
406
  $('.global_setting_score_roundoff').parents('tr').show();
407
+ }else {
408
+ $('.global_setting_score_roundoff').parents('tr').hide();
409
  }
410
  });
411
  $('.global_form_type_settiong select[name="qsm-quiz-settings[form_type]"]').trigger('change');
418
  deleteResults(qid, qname);
419
  });
420
 
421
+ jQuery(document).on('click', '#btn_export', function(e) {
422
+ e.preventDefault();
423
+ jQuery.ajax({
424
+ type: 'POST',
425
+ url: ajaxurl,
426
+ data: {
427
+ action: "qsm_export_data",
428
+ },
429
+ success: function(response) {
430
+ /*
431
+ * Make CSV downloadable
432
+ */
433
+ var d = new Date();
434
+
435
+ var month = d.getMonth() + 1;
436
+ var day = d.getDate();
437
+ var output = d.getFullYear() + '-' + (('' + month).length < 2 ? '0' : '') + month + '-' + (('' + day).length < 2 ? '0' : '') + day;
438
+ var downloadLink = document.createElement("a");
439
+ var fileData = ['\ufeff' + response];
440
+
441
+ var blobObject = new Blob(fileData, {
442
+ type: "text/csv;charset=utf-8;"
443
+ });
444
+
445
+ var url = URL.createObjectURL(blobObject);
446
+ downloadLink.href = url;
447
+ downloadLink.download = "export_" + output + ".csv";
448
+ /*
449
+ * Actually download CSV
450
+ */
451
+ document.body.appendChild(downloadLink);
452
+ downloadLink.click();
453
+ document.body.removeChild(downloadLink);
454
+
455
+
456
+ },
457
+ error: function(errorThrown) {
458
+ alert(errorThrown);
459
+ }
460
+ });
461
+ });
462
+
463
+ jQuery(document).on('click', '#btn_clear_logs', function(e) {
464
+ e.preventDefault();
465
+ var delete_logs=confirm(qsm_logs_delete.qsm_delete_audit_logs);
466
+ if ( delete_logs ) {
467
+ // your deletion code
468
+ jQuery.ajax({
469
+ type: 'POST',
470
+ url: ajaxurl,
471
+ data: {
472
+ action: "qsm_clear_audit_data",
473
+ },
474
+ success: function(response) {
475
+ location.reload();
476
+ },
477
+ error: function(errorThrown) {
478
+ alert(errorThrown);
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');
489
+ var qsm_get_setting_data = jQuery(this).attr('data-auditid');
490
+ jQuery('.qsm_setting__data').html('<p>'+JSON.stringify(JSON.parse(qsm_get_setting_data), null, 2)+'</p>');
491
+ });
492
+
493
  }(jQuery));
494
 
495
  // result page
496
+ jQuery('#results-screen-option-button').on('click', function(event){
497
+ event.preventDefault();
498
+ MicroModal.show('modal-results-screen-option');
499
+ });
500
+ jQuery('#save-results-screen-option-button').on('click', function(event){
501
+ event.preventDefault();
502
+ MicroModal.close('modal-results-screen-option');
503
+ jQuery('#results-screen-option-form').submit();
504
+ });
505
  function deleteResults(id, quizName) {
506
  jQuery("#delete_dialog").dialog({
507
  autoOpen: false,
527
  jQuery("div.mlw_qmn_themeBlockActive").toggleClass("mlw_qmn_themeBlockActive");
528
  jQuery("#mlw_qmn_theme_block_" + theme).toggleClass("mlw_qmn_themeBlockActive");
529
  }
530
+
531
  jQuery(document).ready(function() {
532
  jQuery('.quiz_style_tab').click(function(e) {
533
  e.preventDefault();
538
  jQuery('#' + current_id).show();
539
  });
540
  });
541
+
542
  jQuery(document).ready(function() {
543
  jQuery(document).on('click', '.qsm-activate-theme', function() {
544
  jQuery(this).parents('.theme-wrapper').find('input[name=quiz_theme_id]').prop("checked", true);
546
  jQuery(document).on('input', '.quiz_featured_image', function() {
547
  jQuery('.qsm_featured_image_preview').attr('src', jQuery(this).val());
548
  });
549
+
550
  jQuery(document).on('click', '.filter-links a', function() {
551
  let current_id = jQuery(this).attr('data-id');
552
  jQuery(this).parents('.filter-links').find('li a').each(function() {
562
  });
563
  })
564
  });
565
+
566
  jQuery(document).ready(function () {
567
  jQuery(document).on('click', '.qsm-customize-color-settings', function (e) {
568
  e.preventDefault();
569
+ MicroModal.show('qsm-theme-color-settings');
570
  if( jQuery('.my-color-field').length > 0 ){
571
  jQuery('.my-color-field').wpColorPicker();
572
  }
659
  MicroModal.show('modal-1');
660
  },
661
  };
662
+
663
  QSMQuizzesSurveys.load();
664
 
665
  $('#new_quiz_button_two').on('click', function (event) {
749
  $(document).on('click', '#the-list .qsm-action-link-reset', function (event) {
750
  event.preventDefault();
751
  QSMQuizzesSurveys.openResetPopup($(this).parents('.qsm-quiz-row').data('id'));
752
+ });
753
  $('#reset-stats-button').on('click', function (event) {
754
  event.preventDefault();
755
  $('#reset_quiz_form').submit();
769
  MicroModal.show('modal-bulk-delete');
770
  } else{
771
  $('#posts-filter').submit();
772
+ }
773
  });
774
  $(document).on('click', '.qsm-list-shortcode-view', function (e) {
775
  e.preventDefault();
790
  document.execCommand("copy");
791
  });
792
  $('#bulk-delete-quiz-button').on('click', function (event) {
793
+ event.preventDefault();
794
  if($("#bult-delete-quiz-form input[name='qsm_delete_question_from_qb']").is(":checked")){
795
  $("<input>",{
796
  "type":"hidden",
804
  "name": "qsm_delete_from_db",
805
  "value": "1"
806
  } ).appendTo("#posts-filter");
807
+ }
808
  $('#posts-filter').submit();
809
  });
810
  }
824
  event.preventDefault();
825
  $('#new-quiz-form').submit();
826
  });
827
+
828
  //Hide/show the wizard quiz options
829
  $(document).on('change', '#quiz_settings select', function () {
830
  var value = $(this).val();
834
  jQuery(this).closest('.input-group').next('.input-group').hide();
835
  }
836
  });
837
+
838
  //Show the menus on widget click
839
  $(document).on('click', '.qsm-new_menu_tab_items li', function (e) {
840
  $('.qsm-new_menu_tab_items li').removeClass('active');
844
  $('#' + id).show();
845
  e.preventDefault();
846
  });
847
+
848
  $(document).on('click', '.qsm-wizard-wrap', function (e) {
849
  $('.qsm-wizard-menu .qsm-wizard-wrap').removeClass('active');
850
  $(this).addClass('active');
930
  $('#model-wizard #quiz_settings #disable_scroll_next_previous_click-1').prop('checked', true).parents('.input-group').show();
931
  }
932
  });
933
+
934
  $(document).on('mouseover', '#downloaded_theme .theme-wrapper, #browse_themes .theme-wrapper', function (e) {
935
  e.preventDefault();
936
  if (!$(this).hasClass('active')) {
937
  $(this).find('.theme-name').stop().fadeTo('slow', 1);
938
  }
939
  });
940
+
941
  $(document).on('mouseout', '#downloaded_theme .theme-wrapper, #browse_themes .theme-wrapper', function (e) {
942
  e.preventDefault();
943
  if (!$(this).hasClass('active')) {
944
  $(this).find('.theme-name').stop().fadeTo('slow', 0);
945
  }
946
  });
947
+
948
  $(document).find('#select_themes .theme-actions').remove();
949
+
950
  $(document).on('click', '#new_quiz_button', function () {
951
  $('#quiz_settings').find('.qsm-opt-desc').each(function () {
952
  if ($(this)) {
1015
  $('.multiple-category-notice').show();
1016
  }(jQuery));
1017
 
1018
+ // QSM - Admin Stats Page
1019
  (function ($) {
1020
  if (jQuery('body').hasClass('qsm_page_qmn_stats')) {
1021
  if (window.stats_graph instanceof Chart){
1051
  (function ($) {
1052
  if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1053
  if (window.location.href.indexOf('tab=contact') > 0 ){
1054
+
1055
  QSMContact = {
1056
  load : function() {
1057
  if($.isArray(qsmContactObject.contactForm) && qsmContactObject.contactForm.length > 0){
1061
  }
1062
  },
1063
  addField : function( fieldArray ) {
1064
+ var new_label = fieldArray.label.replace(/"/g, "'");
1065
  var contactField = $( '<div class="contact-form-field new">' +
1066
  '<div class="contact-form-group">' +
1067
  '<label class="contact-form-label">Field Type</label>' +
1114
  contactField.find( '.type-control option[value="date"]').prop( 'selected', true );
1115
  break;
1116
  default:
1117
+
1118
  }
1119
  switch ( fieldArray.use ) {
1120
  case 'name':
1130
  contactField.find( '.use-control option[value="phone"]').prop( 'selected', true );
1131
  break;
1132
  default:
1133
+
1134
  }
1135
  $( '.contact-form' ).append( contactField );
1136
  setTimeout( QSMContact.removeNew, 250 );
1185
  quiz_id : qsmContactObject.quizID,
1186
  nonce : qsmContactObject.saveNonce,
1187
  };
1188
+
1189
  jQuery.post( ajaxurl, data, function( response ) {
1190
  QSMContact.saved( JSON.parse( response ) );
1191
  });
1219
  }
1220
  };
1221
  $(function() {
1222
+
1223
  QSMContact.load();
1224
  if( $('.contact-form > .contact-form-field').length === 0 ){
1225
  $('.save-contact').hide();
1247
  cursor: 'move',
1248
  opacity: 60,
1249
  placeholder: "ui-state-highlight"
1250
+ });
1251
  });
1252
  }
1253
  }
1274
  email_content = wp.editor.getContent( $( this ).find( '.email-template' ).attr( 'id' ) );
1275
  } else {
1276
  email_content = $( this ).find( '.email-template' ).val()
1277
+ }
1278
  email = {
1279
  'conditions': [],
1280
  'to': $( this ).find( '.to-email' ).val(),
1302
  data: data,
1303
  headers: { 'X-WP-Nonce': qsmEmailsObject.nonce },
1304
  })
1305
+ .done(function( results ) {
1306
  if ( results.status ) {
1307
  QSMAdmin.displayAlert( 'Emails were saved!', 'success' );
1308
  } else {
1309
  QSMAdmin.displayAlert( 'There was an error when saving the emails. Please try again.', 'error' );
1310
+ }
1311
  })
1312
  .fail(QSMAdmin.displayjQueryError);
1313
  },
1342
  var template = wp.template( 'email' );
1343
  $( '#qsm_emails' ).append( template( { id: QSMAdminEmails.total, to: to, subject: subject, content: content, replyTo: replyTo } ) );
1344
  conditions.forEach( function( condition, i, conditions) {
1345
+ QSMAdminEmails.addCondition(
1346
+ $( '.qsm-email:last-child' ),
1347
  condition.category,
1348
  condition.criteria,
1349
  condition.operator,
1408
  /**
1409
  * QSM Question Tab
1410
  */
1411
+ var QSMQuestion;
1412
+ var import_button;
1413
  (function ($) {
1414
  if (jQuery('body').hasClass('admin_page_mlw_quiz_options')){
1415
  if (window.location.href.indexOf('tab') == -1 ||window.location.href.indexOf('tab=questions')> 0 ){
1416
+
 
1417
  $.QSMSanitize = function (input) {
1418
  return input.replace(/<(|\/|[^>\/bi]|\/[^>bi]|[^\/>][^>]+|\/[^>][^>]+)>/g, '');
1419
  };
1453
  */
1454
  countTotal: function () {
1455
  var total = 0;
1456
+
1457
  // Cycles through each page.
1458
  _.each(jQuery('.page'), function (page) {
1459
+
1460
  // If page is empty, continue to the next.
1461
  if (0 == jQuery(page).children('.question').length) {
1462
  return;
1648
  var pages = [];
1649
  var qpages = [];
1650
  var pageInfo = null;
1651
+
1652
  // Cycles through each page and add page + questions to pages variable
1653
  _.each(jQuery('.page'), function (page) {
1654
+
1655
  // If page is empty, do not add it.
1656
  if (0 == jQuery(page).children('.question').length) {
1657
  return;
1676
  quiz_id: qsmQuestionSettings.quizID,
1677
  nonce: qsmQuestionSettings.saveNonce,
1678
  };
1679
+
1680
  jQuery.ajax(ajaxurl, {
1681
  data: data,
1682
  method: 'POST',
1751
  } else {
1752
  questionName = new_question_title;
1753
  }
1754
+
1755
  if (questionName == '')
1756
  questionName = 'Your new question!';
1757
+
1758
  $('.page:nth-child(' + page + ')').append(template({
1759
  id: model.id,
1760
  category: model.get('category'),
1799
  var question_title = $('#question_title').val();
1800
  if (name == '' && question_title == '') {
1801
  alert('Enter Question title or description');
1802
+ setTimeout(function () {
1803
+ $('#save-edit-question-spinner').removeClass('is-active');
1804
+ }, 250);
1805
  return false;
1806
  }
1807
  var advanced_option = {};
1834
  var featureImageSrc = $('.qsm-feature-image-src').val();
1835
  var answerType = $('#change-answer-editor').val();
1836
  var matchAnswer = $('#match-answer').val();
1837
+
1838
  var answers = [];
1839
  var $answers = jQuery('.answers-single');
1840
  _.each($answers, function (answer) {
1853
  answer = $answer.find('.answer-text').val().trim();
1854
  answer = $.QSMSanitize(answer);
1855
  }
1856
+
1857
  var points = $answer.find('.answer-points').val();
1858
  var correct = 0;
1859
  if ($answer.find('.answer-correct').prop('checked')) {
1860
  correct = 1;
1861
  }
1862
+
1863
  if (answerType == 'image') {
1864
  answers.push([answer, points, correct, caption]);
1865
  } else {
1866
  answers.push([answer, points, correct]);
1867
  }
1868
+
1869
  });
1870
  $('.questionElements .advanced-content > .qsm-row ').each(function () {
1871
  if ($(this).find('input[type="text"]').length > 0) {
1962
  quiz_system: qsmQuestionSettings.quiz_system
1963
  }));
1964
  }
1965
+
1966
  // show points field only for polar in survey and simple form
1967
  if (qsmQuestionSettings.form_type != 0) {
1968
  if (questionType == 13) {
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];
1978
  wp.editor.remove(textarea_id);
2008
  var questionElements = $('#modal-1-content').html();
2009
  $('#modal-1-content').children().remove();
2010
  CurrentElement.parents('.question').after("<div style='display: none;' class='questionElements'>" + questionElements + "</div>");
2011
+
2012
  //Show question id on question edit screen
2013
  $('#qsm-question-id').text('ID: ' + questionID);
2014
  QSMQuestion.prepareCategories();
2033
  } else {
2034
  jQuery("#question-text").val(questionText);
2035
  }
2036
+
2037
  if ($('#wp-correct_answer_info-wrap').hasClass('html-active')) {
2038
  jQuery("#correct_answer_info").val(answerInfo);
2039
  } else if (CAI_editor) {
2041
  } else {
2042
  jQuery("#correct_answer_info").val(answerInfo);
2043
  }
2044
+
2045
  $('#answers').empty();
2046
  var answers = question.get('answers');
2047
  var answerEditor = question.get('answerEditor');
2106
  if (get_question_title === null || typeof get_question_title === "undefined") {
2107
  get_question_title = '';
2108
  }
2109
+
2110
  //Hide the question settings based on question type
2111
  $('.qsm_hide_for_other').hide();
2112
  if ($('.qsm_show_question_type_' + question.get('type')).length > 0) {
2113
  $('.qsm_show_question_type_' + question.get('type')).show();
2114
  }
2115
+
2116
  qsm_hide_show_question_desc(question.get('type'));
2117
  $('#hint').val(question.get('hint'));
2118
  $("#question_type").val(question.get('type'));
2119
  $("#comments").val(question.get('comments'));
2120
  //Changed checked logic based on new structure for required.
2121
  $("input#required[value='" + question.get('required') + "']").prop('checked', true);
2122
+
2123
  $("#hide_autofill").val(disableAutofill);
2124
  $("#limit_text").val(get_limit_text);
2125
  $("#limit_multiple_response").val(get_limit_mr);
2164
  //MicroModal.show( 'modal-1' );
2165
  $('.questions').sortable('disable');
2166
  $('.page').sortable('disable');
2167
+
2168
  QSMQuestion.sync_child_parent_category(questionID);
2169
+
2170
  jQuery(document).trigger('qsm_open_edit_popup', [questionID, CurrentElement]);
2171
  },
2172
  openEditPagePopup: function (pageID) {
2210
  jQuery(document).trigger('qsm_sync_child_parent_category', [checkbox, questionID]);
2211
  });
2212
  });
2213
+ },
2214
+ question_type_change: function (previous_question_val, questionID) {
2215
+ //you can override this object
2216
  }
2217
  };
2218
+
2219
  $(function () {
2220
  QSMQuestion.pageCollection = Backbone.Collection.extend({
2221
  model: QSMQuestion.page
2230
  event.preventDefault();
2231
  QSMQuestion.addNewPage();
2232
  });
2233
+
2234
  $('.questions').on('click', '.new-question-button', function (event) {
2235
  event.preventDefault();
2236
  QSMQuestion.createQuestion($(this).parents('.page').index());
2237
  $('.save-page-button').trigger('click');
2238
  });
2239
+
2240
  $('.questions').on('click', '.add-question-bank-button', function (event) {
2241
  event.preventDefault();
2242
  QSMQuestion.openQuestionBank($(this).parents('.page').index());
2243
  });
2244
+
2245
  //Show more question on load more
2246
  $(document).on('click', '.qb-load-more-question', function (event) {
2247
  event.preventDefault();
2248
  QSMQuestion.loadQuestionBank();
2249
  });
2250
+
2251
  //Show category related question
2252
  $(document).on('change', '#question-bank-cat', function (event) {
2253
  event.preventDefault();
2254
  QSMQuestion.loadQuestionBank('change');
2255
  });
2256
+
2257
  $('.questions').on('click', '.edit-question-button', function (event) {
2258
  event.preventDefault();
2259
  $('.qsm-category-filter').trigger('keyup');
2263
  event.preventDefault();
2264
  QSMQuestion.openEditPagePopup($(this).parents('.page').data('page-id'));
2265
  });
2266
+
2267
  $(document).on('click', '.questions .duplicate-question-button', function (event) {
2268
  event.preventDefault();
2269
  QSMQuestion.duplicateQuestion($(this).parents('.question').data('question-id'));
2298
  $('.save-page-button').trigger('click');
2299
  MicroModal.close('modal-7');
2300
  });
2301
+
2302
  // unlink question from a particular quiz.
2303
  $('#unlink-question-button').click(function (event) {
2304
  event.preventDefault();
2308
  $('.save-page-button').trigger('click');
2309
  MicroModal.close('modal-7');
2310
  });
2311
+
2312
  $('.questions').on('click', '.delete-page-button', function (event) {
2313
  event.preventDefault();
2314
  if (confirm('Are you sure?')) {
2351
  return false;
2352
  }
2353
  }
2354
+
2355
+
2356
  }
2357
  $('#save-edit-question-spinner').addClass('is-active');
2358
  var model_html = $('#modal-1-content').html();
2359
  $('#modal-1-content').children().remove();
2360
+
2361
  QSMQuestion.saveQuestion($(this).parents('.questionElements').children('#edit_question_id').val(), $(this));
2362
  $('.save-page-button').trigger('click');
2363
  $('#modal-1-content').html(model_html);
2374
  var answer = ['', '', 0, answer_length + 1, question_id, answerType];
2375
  QSMQuestion.addNewAnswer(answer, 0);
2376
  });
2377
+
2378
  $('.qsm-popup-bank').on('click', '.import-button', function (event) {
2379
  event.preventDefault();
2380
  $(this).text('').text('Adding Question');
2382
  QSMQuestion.addQuestionFromQuestionBank($(this).parents('.question-bank-question').data('question-id'));
2383
  $('.import-button').addClass('disable_import');
2384
  });
2385
+
2386
  //Click on selected question button.
2387
  $('.qsm-popup-bank').on('click', '#qsm-import-selected-question', function (event) {
2388
  var $total_selction = $('#question-bank').find('[name="qsm-question-checkbox[]"]:checked').length;
2434
  }
2435
  }
2436
  });
2437
+
2438
  //Select all button.
2439
  $(document).on('change', '#qsm_select_all_question', function (event) {
2440
  $('.qsm-question-checkbox').prop('checked', jQuery('#qsm_select_all_question').prop('checked'));
2441
  });
2442
+
2443
  $('.save-page-button').on('click', function (event) {
2444
  event.preventDefault();
2445
  $('#save-edit-quiz-pages').addClass('is-active');
2461
  MicroModal.close('modal-page-1');
2462
  }
2463
  });
2464
+
2465
  $(document).on('change', '#change-answer-editor', function (event) {
2466
  var newVal = $(this).val();
2467
  if (confirm('All answer will be reset, Do you want to still continue?')) {
2475
  return false;
2476
  }
2477
  });
2478
+
2479
  // Adds event handlers for searching questions
2480
  $('#question_search').on('keyup', function () {
2481
  $('.question').each(function () {
2483
  $(this).hide();
2484
  } else {
2485
  $(this).show();
2486
+ $(this).parent('.page').show();
2487
+
2488
  }
2489
  });
2490
  $('.page').each(function () {
2499
  $('.question').show();
2500
  }
2501
  });
2502
+
2503
  qsm_init_sortable();
2504
+
2505
  if (qsmQuestionSettings.qsm_user_ve === 'true') {
2506
  QSMQuestion.prepareEditor();
2507
  }
2508
  QSMQuestion.loadQuestions();
2509
+
2510
  /**
2511
  * Hide/show advanced option
2512
  */
2520
  }
2521
  });
2522
  });
2523
+
2524
  //Hide the question settings based on question type
2525
+ var previous_question_val;
2526
+ $(document).on('focus', '#question_type', function () {
2527
+ previous_question_val = this.value;
2528
+ })
2529
+ $(document).on('change', '#question_type', function() {
2530
+ var question_val = $('#question_type').val();
2531
+ QSMQuestion.question_type_change(previous_question_val, question_val);
2532
  if (6 == question_val) {
2533
  var question_description = wp.editor.getContent('question-text');
2534
  if (question_description == 'Add description here!') {
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) {
2541
  if (13 == question_val) {
2550
  }
2551
  qsm_hide_show_question_desc(question_val);
2552
  });
2553
+
2554
  //Add new category
2555
  $(document).on('click', '#qsm-category-add-toggle', function () {
2556
  if ($('#qsm-category-add').is(":visible")) {
2561
  $('#qsm-category-add').slideDown('slow');
2562
  }
2563
  });
2564
+
2565
  //Hide/show quesion description
2566
  $(document).on('click', '.qsm-show-question-desc-box', function (e) {
2567
  e.preventDefault();
2583
  $(this).next('.qsm-row').slideDown();
2584
  }
2585
  });
2586
+
2587
  //Open file upload on feature image
2588
  $('body').on('click', '.qsm-feature-image-upl', function (e) {
2589
  e.preventDefault();
2606
  button.next().next().next('.qsm-feature-image-src').val(attachment.url);
2607
  }).open();
2608
  });
2609
+
2610
  // on remove button click
2611
  $('body').on('click', '.qsm-feature-image-rmv', function (e) {
2612
  e.preventDefault();
2615
  button.next().next().val(''); // emptying the hidden field
2616
  button.hide().prev().html('Upload image');
2617
  });
2618
+
2619
  //Hide/show correct answer info
2620
  $(document).on('click', '.qsm-show-correct-info-box', function (e) {
2621
  e.preventDefault();
2632
  //create a new html document (doesn't execute script tags in child elements)
2633
  var doc = document.implementation.createHTMLDocument("");
2634
  var element = doc.createElement('div');
2635
+
2636
  function getText(str) {
2637
  element.innerHTML = str;
2638
  str = element.textContent;
2639
  element.textContent = '';
2640
  return str;
2641
  }
2642
+
2643
  function decodeHTMLEntities(str) {
2644
  if (str && typeof str === 'string') {
2645
  var x = getText(str);
2652
  }
2653
  return decodeHTMLEntities;
2654
  })();
2655
+
2656
  function qsm_hide_show_question_desc(question_type) {
2657
  $('.question-type-description').hide();
2658
  if ($('#question_type_' + question_type + '_description').length > 0) {
2659
  $('#question_type_' + question_type + '_description').show();
2660
  }
2661
  }
2662
+
2663
  function qsm_init_sortable() {
2664
  $('.questions').sortable({
2665
  opacity: 70,
2694
  }
2695
  });
2696
  }
2697
+
2698
  function qsmRandomID(length) {
2699
  var result = '';
2700
  var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2724
  $(this).hide();
2725
  }
2726
  });
2727
+
2728
  }
2729
  });
2730
+
2731
  $(document).on('click', '.add-multiple-category', function (e) {
2732
  e.preventDefault();
2733
  MicroModal.show('modal-9', {
2738
  }
2739
  });
2740
  });
2741
+
2742
  $(document).on('click', '#save-multi-category-button', function (e) {
2743
  e.preventDefault();
2744
  duplicate = false;
2755
  return false;
2756
  }
2757
  });
2758
+
2759
  if (!duplicate) {
2760
  var new_category_data = {
2761
  action: 'save_new_category',
2841
  data: data,
2842
  headers: { 'X-WP-Nonce': qsmResultsObject.nonce },
2843
  })
2844
+ .done(function( results ) {
2845
  if ( results.status ) {
2846
  QSMAdmin.displayAlert( 'Results pages were saved!', 'success' );
2847
  } else {
2848
  QSMAdmin.displayAlert( 'There was an error when saving the results pages. Please try again.', 'error' );
2849
+ }
2850
  })
2851
  .fail(QSMAdmin.displayjQueryError);
2852
  },
2882
  var template = wp.template( 'results-page' );
2883
  $( '#results-pages' ).append( template( { id: QSMAdminResults.total, page: page, redirect: redirect } ) );
2884
  conditions.forEach( function( condition, i, conditions) {
2885
+ QSMAdminResults.addCondition(
2886
  $('.results-page:last-child'),
2887
  condition.category,
2888
  condition.criteria,
2914
  };
2915
  $(function() {
2916
  QSMAdminResults.loadResults();
2917
+
2918
  $( '.add-new-page' ).on( 'click', function( event ) {
2919
  event.preventDefault();
2920
  QSMAdminResults.newResultsPage();
2921
  });
2922
  $( '.save-pages' ).on( 'click', function( event ) {
2923
+ event.preventDefault();
2924
+ QSMAdminResults.saveResults();
2925
  });
2926
  $( '#results-pages' ).on( 'click', '.new-condition', function( event ) {
2927
  event.preventDefault();
js/qsm-common.js CHANGED
@@ -60,6 +60,7 @@
60
  } else {
61
  value = parseInt((max-min)/2) + min ;
62
  }
 
63
  polarQuestion.slider({
64
  max: max,
65
  min: min,
@@ -70,32 +71,42 @@
70
  slide: function slider_slide(event, ui) {
71
  if('answer'=== page || 'admin' === page){
72
  return false;
 
 
 
 
73
  }
74
  },
75
  change: function ( event, ui ){
76
  if('answer'!== page || 'admin' !== page){
77
  qsmPolarSliderQuestionChange(ui,questionID, answer1, answer2, value , isReverse );
 
78
  }
79
  },
80
  create: function (event, ui){
81
  if('answer'=== page){
82
  jQuery(document).trigger('qsm_after_display_result',[ this, ui ]);
 
 
83
  } else if ( 'admin' === page ) {
84
  jQuery(this).find('a').css({'display':'flex','align-items':'center','justify-content':'center','text-decoration':'none','color':'white'});
85
  jQuery(this).find('a').html('<p style="margin:0;">'+value+'</p>');
86
  } else {
87
- qsmPolarSliderQuestionCreate(questionID, '' );
88
  }
89
  if ( isNaN(value) ){
90
  jQuery(this).find('a').hide();
91
  }
92
  }
 
93
  });
94
  }
95
 
96
  function qsmPolarSliderQuestionChange(ui,questionID, answer1, answer2, value , isReverse){
97
  jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
98
  '.qmn_polar').val(ui.value);
 
 
99
  let lowerMidClass = '.left-polar-title';
100
  let upperMidClass = '.right-polar-title';
101
  if (isReverse){
@@ -130,12 +141,11 @@
130
  }
131
  }
132
 
133
- function qsmPolarSliderQuestionCreate(questionID, value){
 
134
  jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
135
  '.left-polar-title').css('font-weight', '400');
136
  jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
137
  '.right-polar-title').css('font-weight', '400');
138
- jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
139
- '.qmn_polar').val(value);
140
  }
141
  }(jQuery));
60
  } else {
61
  value = parseInt((max-min)/2) + min ;
62
  }
63
+
64
  polarQuestion.slider({
65
  max: max,
66
  min: min,
71
  slide: function slider_slide(event, ui) {
72
  if('answer'=== page || 'admin' === page){
73
  return false;
74
+ }
75
+ else{
76
+ jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
77
+ '.ui-slider-handle').text( ui.value );
78
  }
79
  },
80
  change: function ( event, ui ){
81
  if('answer'!== page || 'admin' !== page){
82
  qsmPolarSliderQuestionChange(ui,questionID, answer1, answer2, value , isReverse );
83
+
84
  }
85
  },
86
  create: function (event, ui){
87
  if('answer'=== page){
88
  jQuery(document).trigger('qsm_after_display_result',[ this, ui ]);
89
+ jQuery(this).find('a').css({'display':'flex','align-items':'center','justify-content':'center','text-decoration':'none','color':'white'});
90
+ jQuery(this).find('a').html('<p style="margin:0;">'+value+'</p>');
91
  } else if ( 'admin' === page ) {
92
  jQuery(this).find('a').css({'display':'flex','align-items':'center','justify-content':'center','text-decoration':'none','color':'white'});
93
  jQuery(this).find('a').html('<p style="margin:0;">'+value+'</p>');
94
  } else {
95
+ qsmPolarSliderQuestionCreate(questionID );
96
  }
97
  if ( isNaN(value) ){
98
  jQuery(this).find('a').hide();
99
  }
100
  }
101
+
102
  });
103
  }
104
 
105
  function qsmPolarSliderQuestionChange(ui,questionID, answer1, answer2, value , isReverse){
106
  jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
107
  '.qmn_polar').val(ui.value);
108
+ jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
109
+ '.ui-slider-handle').text(ui.value);
110
  let lowerMidClass = '.left-polar-title';
111
  let upperMidClass = '.right-polar-title';
112
  if (isReverse){
141
  }
142
  }
143
 
144
+ function qsmPolarSliderQuestionCreate(questionID){
145
+
146
  jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
147
  '.left-polar-title').css('font-weight', '400');
148
  jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
149
  '.right-polar-title').css('font-weight', '400');
 
 
150
  }
151
  }(jQuery));
js/qsm-quiz.js CHANGED
@@ -7,1528 +7,1528 @@
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].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';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.6
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.6
13
  * @package QSM
14
  */
15
 
@@ -24,10 +24,10 @@ define( 'QSM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
24
  define( 'hide_qsm_adv', true );
25
  define( 'QSM_THEME_PATH', plugin_dir_path( __DIR__ ) );
26
  define( 'QSM_THEME_SLUG', plugins_url( '/' ) );
27
- define('QSM_PLUGIN_CSS_URL', QSM_PLUGIN_URL . 'css');
28
- define('QSM_PLUGIN_JS_URL', QSM_PLUGIN_URL . 'js');
29
- define('QSM_PLUGIN_PHP_DIR', QSM_THEME_PATH . 'php');
30
- define('QSM_PLUGIN_TXTDOMAIN', 'quiz-master-next');
31
 
32
  /**
33
  * This class is the main class of the plugin
@@ -45,7 +45,7 @@ class MLWQuizMasterNext {
45
  * @var string
46
  * @since 4.0.0
47
  */
48
- public $version = '7.3.6';
49
 
50
  /**
51
  * QSM Alert Manager Object
@@ -252,16 +252,16 @@ class MLWQuizMasterNext {
252
  */
253
  public function qsm_admin_scripts_style( $hook ) {
254
  global $mlwQuizMasterNext;
255
- //admin styles
256
  wp_enqueue_style( 'qsm_admin_style', plugins_url( 'css/qsm-admin.css', __FILE__ ), array(), $this->version );
257
  wp_style_add_data( 'qsm_admin_style', 'rtl', 'replace' );
258
- //dashboard and quiz list pages
259
  if ( 'toplevel_page_qsm_dashboard' === $hook || 'qsm_page_mlw_quiz_list' === $hook ) {
260
- wp_enqueue_script( 'micromodal_script', plugins_url( 'js/micromodal.min.js', __FILE__ ), array( 'jquery', 'qsm_admin_js' ), $this->version, true);
261
  wp_enqueue_media();
262
- wp_enqueue_style( 'qsm_admin_dashboard_css', QSM_PLUGIN_CSS_URL.'/admin-dashboard.css', array(), $this->version );
263
  wp_style_add_data( 'qsm_admin_dashboard_css', 'rtl', 'replace' );
264
- wp_enqueue_style( 'qsm_ui_css', QSM_PLUGIN_CSS_URL.'/jquery-ui.min.css', array(), '1.13.0' );
265
  }
266
  // dashboard
267
  if ( 'toplevel_page_qsm_dashboard' === $hook ) {
@@ -272,31 +272,32 @@ class MLWQuizMasterNext {
272
  }
273
  // result details page
274
  if ( 'admin_page_qsm_quiz_result_details' === $hook ) {
275
- wp_enqueue_style( 'qsm_common_style', QSM_PLUGIN_CSS_URL.'/common.css', array(), $this->version );
276
  wp_style_add_data( 'qsm_common_style', 'rtl', 'replace' );
277
- wp_enqueue_script( 'math_jax', QSM_PLUGIN_JS_URL.'/mathjax/tex-mml-chtml.js', false , '3.2.0' , true );
278
- wp_enqueue_script( 'jquery-ui-slider');
279
- wp_enqueue_script( 'jquery-ui-slider-rtl-js', QSM_PLUGIN_JS_URL.'/jquery.ui.slider-rtl.js',array( 'jquery-ui-core', 'jquery-ui-mouse', 'jquery-ui-slider' ), $this->version, true);
280
- wp_enqueue_style( 'jquery-ui-slider-rtl-css', QSM_PLUGIN_CSS_URL.'/jquery.ui.slider-rtl.css', array(), $this->version );
281
- wp_enqueue_script( 'qsm_common', QSM_PLUGIN_JS_URL.'/qsm-common.js', array(), $this->version, true );
282
- wp_enqueue_style( 'jquery-redmond-theme', QSM_PLUGIN_CSS_URL.'/jquery-ui.css', array(), $this->version );
283
  }
284
- //results page
285
  if ( 'qsm_page_mlw_quiz_results' === $hook ) {
286
  wp_enqueue_script( 'jquery' );
287
  wp_enqueue_script( 'jquery-ui-core' );
288
  wp_enqueue_script( 'jquery-ui-dialog' );
289
  wp_enqueue_script( 'jquery-ui-button' );
290
- wp_enqueue_style( 'qmn_jquery_redmond_theme', QSM_PLUGIN_CSS_URL.'/jquery-ui.css', array(), $this->version);
 
291
  }
292
- //stats page
293
  if ( 'qsm_page_qmn_stats' === $hook ) {
294
- wp_enqueue_script('ChartJS', QSM_PLUGIN_JS_URL.'/chart.min.js', array(),'3.6.0',true);
295
  }
296
- //quiz option pages
297
  if ( 'admin_page_mlw_quiz_options' === $hook ) {
298
  wp_enqueue_script( 'wp-tinymce' );
299
- wp_enqueue_script( 'micromodal_script', plugins_url( 'js/micromodal.min.js', __FILE__ ), array( 'jquery', 'qsm_admin_js' ), $this->version, true);
300
  $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'questions';
301
  switch ( $current_tab ) {
302
  case 'contact':
@@ -334,8 +335,10 @@ class MLWQuizMasterNext {
334
  break;
335
  }
336
  }
337
- //load admin JS after all dependencies are loaded
338
  wp_enqueue_script( 'qsm_admin_js', plugins_url( 'js/qsm-admin.js', __FILE__ ), array( 'jquery', 'backbone', 'underscore', 'wp-util', 'jquery-ui-sortable' ), $this->version, true );
 
 
339
  }
340
 
341
  /**
@@ -525,15 +528,17 @@ class MLWQuizMasterNext {
525
  <p>
526
  <?php esc_html_e( 'QSM has been updated!', 'quiz-master-next' ); ?><br>
527
  <?php esc_html_e( 'We need to upgrade your database so that you can enjoy the latest features.', 'quiz-master-next' ); ?><br>
528
- <?php /* translators: %s: HTML tag */
529
- echo sprintf( esc_html__( 'Please note that this action %1$s can not be %2$s rolled back. We recommend you to take a backup of your current site before proceeding.', 'quiz-master-next' ), '<b>', '</b>'); ?>
 
 
530
  </p>
531
  <p class="category-action">
532
  <a href="#" class="button cancel-multiple-category"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></a>
533
  &nbsp;&nbsp;&nbsp;<a href="#" class="button button-primary enable-multiple-category"><?php esc_html_e( 'Update Database', 'quiz-master-next' ); ?></a>
534
  </p>
535
  </div>
536
- <?php
537
  }
538
  }
539
 
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
 
24
  define( 'hide_qsm_adv', true );
25
  define( 'QSM_THEME_PATH', plugin_dir_path( __DIR__ ) );
26
  define( 'QSM_THEME_SLUG', plugins_url( '/' ) );
27
+ define( 'QSM_PLUGIN_CSS_URL', QSM_PLUGIN_URL . 'css' );
28
+ define( 'QSM_PLUGIN_JS_URL', QSM_PLUGIN_URL . 'js' );
29
+ define( 'QSM_PLUGIN_PHP_DIR', QSM_THEME_PATH . 'php' );
30
+ define( 'QSM_PLUGIN_TXTDOMAIN', 'quiz-master-next' );
31
 
32
  /**
33
  * This class is the main class of the plugin
45
  * @var string
46
  * @since 4.0.0
47
  */
48
+ public $version = '7.3.7';
49
 
50
  /**
51
  * QSM Alert Manager Object
252
  */
253
  public function qsm_admin_scripts_style( $hook ) {
254
  global $mlwQuizMasterNext;
255
+ // admin styles
256
  wp_enqueue_style( 'qsm_admin_style', plugins_url( 'css/qsm-admin.css', __FILE__ ), array(), $this->version );
257
  wp_style_add_data( 'qsm_admin_style', 'rtl', 'replace' );
258
+ // dashboard and quiz list pages
259
  if ( 'toplevel_page_qsm_dashboard' === $hook || 'qsm_page_mlw_quiz_list' === $hook ) {
260
+ wp_enqueue_script( 'micromodal_script', plugins_url( 'js/micromodal.min.js', __FILE__ ), array( 'jquery', 'qsm_admin_js' ), $this->version, true );
261
  wp_enqueue_media();
262
+ wp_enqueue_style( 'qsm_admin_dashboard_css', QSM_PLUGIN_CSS_URL . '/admin-dashboard.css', array(), $this->version );
263
  wp_style_add_data( 'qsm_admin_dashboard_css', 'rtl', 'replace' );
264
+ wp_enqueue_style( 'qsm_ui_css', QSM_PLUGIN_CSS_URL . '/jquery-ui.min.css', array(), '1.13.0' );
265
  }
266
  // dashboard
267
  if ( 'toplevel_page_qsm_dashboard' === $hook ) {
272
  }
273
  // result details page
274
  if ( 'admin_page_qsm_quiz_result_details' === $hook ) {
275
+ wp_enqueue_style( 'qsm_common_style', QSM_PLUGIN_CSS_URL . '/common.css', array(), $this->version );
276
  wp_style_add_data( 'qsm_common_style', 'rtl', 'replace' );
277
+ wp_enqueue_script( 'math_jax', QSM_PLUGIN_JS_URL . '/mathjax/tex-mml-chtml.js', false, '3.2.0', true );
278
+ wp_enqueue_script( 'jquery-ui-slider' );
279
+ wp_enqueue_script( 'jquery-ui-slider-rtl-js', QSM_PLUGIN_JS_URL . '/jquery.ui.slider-rtl.js', array( 'jquery-ui-core', 'jquery-ui-mouse', 'jquery-ui-slider' ), $this->version, true );
280
+ wp_enqueue_style( 'jquery-ui-slider-rtl-css', QSM_PLUGIN_CSS_URL . '/jquery.ui.slider-rtl.css', array(), $this->version );
281
+ wp_enqueue_script( 'qsm_common', QSM_PLUGIN_JS_URL . '/qsm-common.js', array(), $this->version, true );
282
+ wp_enqueue_style( 'jquery-redmond-theme', QSM_PLUGIN_CSS_URL . '/jquery-ui.css', array(), $this->version );
283
  }
284
+ // results page
285
  if ( 'qsm_page_mlw_quiz_results' === $hook ) {
286
  wp_enqueue_script( 'jquery' );
287
  wp_enqueue_script( 'jquery-ui-core' );
288
  wp_enqueue_script( 'jquery-ui-dialog' );
289
  wp_enqueue_script( 'jquery-ui-button' );
290
+ wp_enqueue_style( 'qmn_jquery_redmond_theme', QSM_PLUGIN_CSS_URL . '/jquery-ui.css', array(), $this->version );
291
+ wp_enqueue_script( 'micromodal_script', QSM_PLUGIN_JS_URL . '/micromodal.min.js', array( 'jquery' ), $this->version, true );
292
  }
293
+ // stats page
294
  if ( 'qsm_page_qmn_stats' === $hook ) {
295
+ wp_enqueue_script( 'ChartJS', QSM_PLUGIN_JS_URL . '/chart.min.js', array(), '3.6.0', true );
296
  }
297
+ // quiz option pages
298
  if ( 'admin_page_mlw_quiz_options' === $hook ) {
299
  wp_enqueue_script( 'wp-tinymce' );
300
+ wp_enqueue_script( 'micromodal_script', plugins_url( 'js/micromodal.min.js', __FILE__ ), array( 'jquery', 'qsm_admin_js' ), $this->version, true );
301
  $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'questions';
302
  switch ( $current_tab ) {
303
  case 'contact':
335
  break;
336
  }
337
  }
338
+ // load admin JS after all dependencies are loaded
339
  wp_enqueue_script( 'qsm_admin_js', plugins_url( 'js/qsm-admin.js', __FILE__ ), array( 'jquery', 'backbone', 'underscore', 'wp-util', 'jquery-ui-sortable' ), $this->version, true );
340
+ wp_enqueue_script( 'micromodal_script', plugins_url( 'js/micromodal.min.js', __FILE__ ), array( 'jquery', 'qsm_admin_js' ), $this->version, true );
341
+
342
  }
343
 
344
  /**
528
  <p>
529
  <?php esc_html_e( 'QSM has been updated!', 'quiz-master-next' ); ?><br>
530
  <?php esc_html_e( 'We need to upgrade your database so that you can enjoy the latest features.', 'quiz-master-next' ); ?><br>
531
+ <?php
532
+ /* translators: %s: HTML tag */
533
+ echo sprintf( esc_html__( 'Please note that this action %1$s can not be %2$s rolled back. We recommend you to take a backup of your current site before proceeding.', 'quiz-master-next' ), '<b>', '</b>' );
534
+ ?>
535
  </p>
536
  <p class="category-action">
537
  <a href="#" class="button cancel-multiple-category"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></a>
538
  &nbsp;&nbsp;&nbsp;<a href="#" class="button button-primary enable-multiple-category"><?php esc_html_e( 'Update Database', 'quiz-master-next' ); ?></a>
539
  </p>
540
  </div>
541
+ <?php
542
  }
543
  }
544
 
php/admin/admin-results-details-page.php CHANGED
@@ -31,7 +31,8 @@ function qsm_generate_result_details() {
31
  $active_class = ' nav-tab-active';
32
  }
33
  $result_id = isset( $_GET["result_id"] ) ? intval( $_GET["result_id"] ) : '';
34
- echo '<a href="?page=qsm_quiz_result_details&result_id="' . esc_attr( $result_id ) . '"&tab="' . esc_attr( $tab['slug'] ) . '" class="nav-tab' . esc_attr( $active_class ) . '">' . esc_html( $tab['title'] ) . '</a>';
 
35
  }
36
  ?>
37
  </h2>
31
  $active_class = ' nav-tab-active';
32
  }
33
  $result_id = isset( $_GET["result_id"] ) ? intval( $_GET["result_id"] ) : '';
34
+
35
+ echo '<a href="?page=qsm_quiz_result_details&result_id='.esc_attr( $result_id ).'&tab='.esc_attr( $tab['slug'] ).'" class="nav-tab '.esc_attr( $active_class ).'">' . esc_html( $tab['title'] ) . '</a>';
36
  }
37
  ?>
38
  </h2>
php/admin/admin-results-page.php CHANGED
@@ -23,7 +23,10 @@ function qsm_generate_admin_results_page() {
23
 
24
  ?>
25
  <div class="wrap">
26
- <h2><?php esc_html_e( 'Quiz Results', 'quiz-master-next' ); ?></h2>
 
 
 
27
  <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
28
  <?php qsm_show_adverts(); ?>
29
  <h2 class="nav-tab-wrapper">
@@ -111,7 +114,7 @@ function qsm_results_overview_tab_content() {
111
  $mlwQuizMasterNext->log_manager->add( 'Error deleting result', "Tried {$wpdb->last_query} but got $error.", 0, 'error' );
112
  } else {
113
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your results has been deleted successfully.', 'quiz-master-next' ), 'success' );
114
- $mlwQuizMasterNext->audit_manager->new_audit( "Results Has Been Deleted From: $mlw_delete_results_name" );
115
 
116
  }
117
  }
@@ -148,7 +151,7 @@ function qsm_results_overview_tab_content() {
148
  }
149
  }
150
 
151
- $mlwQuizMasterNext->audit_manager->new_audit( "Results Have Been Bulk Deleted" );
152
  }
153
  }
154
 
@@ -301,6 +304,31 @@ function qsm_results_overview_tab_content() {
301
  </p>
302
  </form>
303
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
  <form action="" method="post" name="bulk_delete_form">
306
  <input type="hidden" name="bulk_delete" value="confirmation" />
@@ -317,11 +345,31 @@ function qsm_results_overview_tab_content() {
317
  'user' => __( 'User', 'quiz-master-next' ),
318
  'time_taken' => __( 'Time Taken', 'quiz-master-next' ),
319
  'ip' => __( 'IP Address', 'quiz-master-next' ),
 
 
320
  ) );
321
 
322
  $values = $quiz_infos = [];
323
  foreach ( $th_elements as $key => $th ) {
324
  $values[ $key ]['title'] = $th;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  }
326
 
327
  if ( $mlw_quiz_data ) {
@@ -400,9 +448,14 @@ function qsm_results_overview_tab_content() {
400
  if ( isset( $values['ip'] ) ) {
401
  $values['ip']['content'][] = $mlw_quiz_info->user_ip;
402
  }
403
-
 
 
 
 
 
404
  foreach ( $values as $k => $v ) {
405
- if ( ! in_array( $k, [ 'score', 'time_complete', 'name', 'business', 'email', 'phone', 'user', 'time_taken', 'ip' ], true ) ) {
406
  $content = apply_filters( 'mlw_qmn_admin_results_page_column_content', '', $mlw_quiz_info, $k );
407
  if ( isset( $values[ $k ] ) && ! empty( $content ) ) {
408
  $values[ $k ]['content'][] = $content;
@@ -419,7 +472,7 @@ function qsm_results_overview_tab_content() {
419
  <th><?php esc_html_e( 'Quiz Name','quiz-master-next' ); ?></th>
420
  <?php foreach ( $values as $k => $v ) {
421
  if ( ! empty( $v['content'] ) ) {
422
- echo '<th>' . esc_html( $v['title'] ) . '</th>';
423
  }
424
  } ?>
425
  </tr>
@@ -435,7 +488,7 @@ function qsm_results_overview_tab_content() {
435
  <?php
436
  foreach ( $values as $k => $v ) {
437
  if ( isset( $v['content'][ $x ] ) ) {
438
- echo '<td><span style="font-size:16px;">' . wp_kses_post( apply_filters( 'mlw_qmn_admin_results_page_result', $v['content'][ $x ], $quiz_infos[ $x ], $k ) ) . '</span></td>';
439
  }
440
  } ?>
441
  </tr><?php
@@ -459,6 +512,50 @@ function qsm_results_overview_tab_content() {
459
  value='<?php esc_html_e( 'Delete Results', 'quiz-master-next' ); ?>' /></p>
460
  </form>
461
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  <?php
463
  }
464
  ?>
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(); ?>
32
  <h2 class="nav-tab-wrapper">
114
  $mlwQuizMasterNext->log_manager->add( 'Error deleting result', "Tried {$wpdb->last_query} but got $error.", 0, 'error' );
115
  } else {
116
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your results has been deleted successfully.', 'quiz-master-next' ), 'success' );
117
+ $mlwQuizMasterNext->audit_manager->new_audit( "Results Has Been Deleted From:", $mlw_delete_results_name, "" );
118
 
119
  }
120
  }
151
  }
152
  }
153
 
154
+ $mlwQuizMasterNext->audit_manager->new_audit( "Results Have Been Bulk Deleted", "", "" );
155
  }
156
  }
157
 
304
  </p>
305
  </form>
306
  </div>
307
+ <?php
308
+ //process screen options
309
+ $user_id = get_current_user_id();
310
+ if ( isset($_POST["results-screen_option_nonce"]) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST["results-screen_option_nonce"] ) ), 'results_screen_option' ) ) {
311
+ $results_screen_option['page_url'] = isset($_POST['page_url']) ? sanitize_text_field( wp_unslash( $_POST['page_url'] ) ) : "0";
312
+ $results_screen_option['page_name'] = isset($_POST['page_name']) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : "0";
313
+ $results_screen_option['business'] = isset($_POST['business']) ? sanitize_text_field( wp_unslash( $_POST['business'] ) ) : "0";
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',
324
+ 'page_name' => '0',
325
+ 'business' => '1',
326
+ 'phone' => '1',
327
+ 'ip_address' => '1',
328
+ );
329
+ }
330
+ }
331
+ ?>
332
 
333
  <form action="" method="post" name="bulk_delete_form">
334
  <input type="hidden" name="bulk_delete" value="confirmation" />
345
  'user' => __( 'User', 'quiz-master-next' ),
346
  'time_taken' => __( 'Time Taken', 'quiz-master-next' ),
347
  'ip' => __( 'IP Address', 'quiz-master-next' ),
348
+ 'page_name' => __( 'Page Name', 'quiz-master-next' ),
349
+ 'page_url' => __( 'Page URL', 'quiz-master-next' ),
350
  ) );
351
 
352
  $values = $quiz_infos = [];
353
  foreach ( $th_elements as $key => $th ) {
354
  $values[ $key ]['title'] = $th;
355
+ $values[ $key ]['style'] = "";
356
+ }
357
+
358
+ $display_none = ' style=display:none; ';
359
+ if ( "0" === $results_screen_option['page_url'] ) {
360
+ $values['page_url']['style'] = $display_none;
361
+ }
362
+ if ( "0" === $results_screen_option['page_name'] ) {
363
+ $values['page_name']['style'] = $display_none;
364
+ }
365
+ if ( "0" === $results_screen_option['business'] ) {
366
+ $values['business']['style'] = $display_none ;
367
+ }
368
+ if ( "0" === $results_screen_option['phone'] ) {
369
+ $values['phone']['style'] = $display_none ;
370
+ }
371
+ if ( "0" === $results_screen_option['ip_address'] ) {
372
+ $values['ip']['style'] = $display_none ;
373
  }
374
 
375
  if ( $mlw_quiz_data ) {
448
  if ( isset( $values['ip'] ) ) {
449
  $values['ip']['content'][] = $mlw_quiz_info->user_ip;
450
  }
451
+ if ( isset( $values['page_name'] ) ) {
452
+ $values['page_name']['content'][] = $mlw_quiz_info->page_name;
453
+ }
454
+ if ( isset( $values['page_url'] ) ) {
455
+ $values['page_url']['content'][] = '<a href="' . esc_url( $mlw_quiz_info->page_url ) . '">' . esc_html( $mlw_quiz_info->page_url ) . '</a>';
456
+ }
457
  foreach ( $values as $k => $v ) {
458
+ if ( ! in_array( $k, [ 'score', 'time_complete', 'name', 'business', 'email', 'phone', 'user', 'time_taken', 'ip', 'page_name', 'page_url' ], true ) ) {
459
  $content = apply_filters( 'mlw_qmn_admin_results_page_column_content', '', $mlw_quiz_info, $k );
460
  if ( isset( $values[ $k ] ) && ! empty( $content ) ) {
461
  $values[ $k ]['content'][] = $content;
472
  <th><?php esc_html_e( 'Quiz Name','quiz-master-next' ); ?></th>
473
  <?php foreach ( $values as $k => $v ) {
474
  if ( ! empty( $v['content'] ) ) {
475
+ echo '<th'. esc_html( $v['style'] ) . '>'. esc_html( $v['title'] ) . '</th>';
476
  }
477
  } ?>
478
  </tr>
488
  <?php
489
  foreach ( $values as $k => $v ) {
490
  if ( isset( $v['content'][ $x ] ) ) {
491
+ echo '<td'. esc_html( $v['style'] ) . '><span style="font-size:16px;">' . wp_kses_post( apply_filters( 'mlw_qmn_admin_results_page_result', $v['content'][ $x ], $quiz_infos[ $x ], $k ) ) . '</span></td>';
492
  }
493
  } ?>
494
  </tr><?php
512
  value='<?php esc_html_e( 'Delete Results', 'quiz-master-next' ); ?>' /></p>
513
  </form>
514
  </div>
515
+
516
+ <!-- Popup for screen options -->
517
+ <div class="qsm-popup qsm-popup-slide" id="modal-results-screen-option" aria-hidden="true">
518
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
519
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-results-screen-option-title">
520
+ <header class="qsm-popup__header">
521
+ <h2 class="qsm-popup__title" id="modal-results-screen-option-title"><?php esc_html_e( 'Choose Columns to hide/show', 'quiz-master-next' ); ?></h2>
522
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
523
+ </header>
524
+ <main class="qsm-popup__content" id="modal-results-screen-option-content">
525
+ <form action='' method='post' id="results-screen-option-form" style="display:flex; flex-direction:column;">
526
+ <label>
527
+ <input type="checkbox" value="1" name="page_url" <?php checked( $results_screen_option['page_url'], "1", true )?>/>
528
+ <?php esc_html_e( 'Page URL', 'quiz-master-next' ); ?>
529
+ </label>
530
+ <label>
531
+ <input type="checkbox" name="page_name" value="1" <?php checked( $results_screen_option['page_name'], "1", true )?>/>
532
+ <?php esc_html_e( 'Page Name', 'quiz-master-next' ); ?>
533
+ </label>
534
+ <label>
535
+ <input type="checkbox" value="1" name="business" <?php checked( $results_screen_option['business'], "1", true )?>/>
536
+ <?php esc_html_e( 'Business', 'quiz-master-next' ); ?>
537
+ </label>
538
+ <label>
539
+ <input type="checkbox" name="phone" value="1" <?php checked( $results_screen_option['phone'], "1", true )?>/>
540
+ <?php esc_html_e( 'Phone', 'quiz-master-next' ); ?>
541
+ </label>
542
+ <label>
543
+ <input type="checkbox" name="ip_address" value="1" <?php checked( $results_screen_option['ip_address'], "1", true )?>/>
544
+ <?php esc_html_e( 'IP Address', 'quiz-master-next' ); ?>
545
+ </label>
546
+ <?php wp_nonce_field( 'results_screen_option', 'results-screen_option_nonce' ); ?>
547
+ </form>
548
+ </main>
549
+ <footer class="qsm-popup__footer">
550
+ <button id="save-results-screen-option-button"
551
+ class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Save', 'quiz-master-next' ); ?></button>
552
+ <button class="qsm-popup__btn" data-micromodal-close
553
+ aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
554
+ </footer>
555
+ </div>
556
+ </div>
557
+ </div>
558
+
559
  <?php
560
  }
561
  ?>
php/admin/dashboard-widgets.php CHANGED
@@ -1,17 +1,19 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
3
 
4
  /**
5
- * This function adds a widget to the dashboard in WordPress.
6
- *
7
- * @return void
8
- * @since 4.4.0
9
- */
10
  function qmn_add_dashboard_widget() {
11
  if ( current_user_can( 'publish_posts' ) ) {
12
  wp_add_dashboard_widget(
13
  'qmn_snapshot_widget',
14
- __('Quiz And Survey Master Snapshot', 'quiz-master-next'),
15
  'qmn_snapshot_dashboard_widget'
16
  );
17
  }
@@ -20,81 +22,78 @@ function qmn_add_dashboard_widget() {
20
  add_action( 'wp_dashboard_setup', 'qmn_add_dashboard_widget' );
21
 
22
  /**
23
- * This function creates the actual widget that is added to the dashboard.
24
- *
25
- * This widget adds things like the most popular/least popular quiz. How many people have taken the quiz etc.
26
- * @param type description
27
- * @return type description
28
- * @since 4.4.0
29
- */
 
30
  function qmn_snapshot_dashboard_widget() {
31
  global $wpdb;
32
- $mlw_qmn_today_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", gmdate( "Y-m-d", current_time( 'timestamp' ) ), gmdate( "Y-m-d", current_time( 'timestamp' ) ) ) );
33
- $mlw_last_week = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 7, gmdate("Y"));
34
- $mlw_last_week = gmdate("Y-m-d", $mlw_last_week);
35
  $mlw_qmn_last_weekday_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_week, $mlw_last_week ) );
36
  if ( 0 != intval( $mlw_qmn_last_weekday_taken ) ) {
37
- $mlw_qmn_analyze_today = round((($mlw_qmn_today_taken - $mlw_qmn_last_weekday_taken) / $mlw_qmn_last_weekday_taken) * 100, 2);
38
- }
39
- else {
40
  $mlw_qmn_analyze_today = $mlw_qmn_today_taken * 100;
41
  }
42
 
43
- $mlw_this_week = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 6, gmdate("Y"));
44
- $mlw_this_week = gmdate("Y-m-d", $mlw_this_week);
45
- $mlw_qmn_this_week_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_this_week, gmdate("Y-m-d") ) );
46
 
47
- $mlw_last_week_start = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 13, gmdate("Y"));
48
- $mlw_last_week_start = gmdate("Y-m-d", $mlw_last_week_start);
49
- $mlw_last_week_end = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 7, gmdate("Y"));
50
- $mlw_last_week_end = gmdate("Y-m-d", $mlw_last_week_end);
51
  $mlw_qmn_last_week_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_week_start, $mlw_last_week_end ) );
52
 
53
  if ( 0 !== intval( $mlw_qmn_last_week_taken ) ) {
54
- $mlw_qmn_analyze_week = round((($mlw_qmn_this_week_taken - $mlw_qmn_last_week_taken) / $mlw_qmn_last_week_taken) * 100, 2);
55
- }
56
- else {
57
  $mlw_qmn_analyze_week = $mlw_qmn_this_week_taken * 100;
58
  }
59
 
60
- $mlw_this_month = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 29, gmdate("Y"));
61
- $mlw_this_month = gmdate("Y-m-d", $mlw_this_month);
62
- $mlw_qmn_this_month_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_this_month, gmdate("Y-m-d") ) );
63
 
64
- $mlw_last_month_start = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 59, gmdate("Y"));
65
- $mlw_last_month_start = gmdate("Y-m-d", $mlw_last_month_start);
66
- $mlw_last_month_end = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 30, gmdate("Y"));
67
- $mlw_last_month_end = gmdate("Y-m-d", $mlw_last_month_end);
68
  $mlw_qmn_last_month_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_month_start, $mlw_last_month_end ) );
69
 
70
  if ( 0 != intval( $mlw_qmn_last_month_taken ) ) {
71
- $mlw_qmn_analyze_month = round((($mlw_qmn_this_month_taken - $mlw_qmn_last_month_taken) / $mlw_qmn_last_month_taken) * 100, 2);
72
- }
73
- else {
74
  $mlw_qmn_analyze_month = $mlw_qmn_this_month_taken * 100;
75
  }
76
 
77
- $mlw_this_quater = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 89, gmdate("Y"));
78
- $mlw_this_quater = gmdate("Y-m-d", $mlw_this_quater);
79
- $mlw_qmn_this_quater_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_this_quater, gmdate("Y-m-d") ));
80
 
81
- $mlw_last_quater_start = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 179, gmdate("Y"));
82
- $mlw_last_quater_start = gmdate("Y-m-d", $mlw_last_quater_start);
83
- $mlw_last_quater_end = mktime(0, 0, 0, gmdate("m") , gmdate("d") - 90, gmdate("Y"));
84
- $mlw_last_quater_end = gmdate("Y-m-d", $mlw_last_quater_end);
85
  $mlw_qmn_last_quater_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_quater_start, $mlw_last_quater_end ) );
86
 
87
  if ( 0 != intval( $mlw_qmn_last_quater_taken ) ) {
88
- $mlw_qmn_analyze_quater = round((($mlw_qmn_this_quater_taken - $mlw_qmn_last_quater_taken) / $mlw_qmn_last_quater_taken) * 100, 2);
89
- }
90
- else {
91
  $mlw_qmn_analyze_quater = $mlw_qmn_this_quater_taken * 100;
92
  }
93
 
94
  $mlw_stat_total_active_quiz = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_quizzes WHERE deleted=0 LIMIT 1" );
95
- $mlw_stat_total_questions = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_questions WHERE deleted=0 LIMIT 1" );
96
 
97
- $mlw_stat_most_popular_quiz = $wpdb->get_row( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE deleted=0 ORDER BY quiz_taken Desc LIMIT 1" );
98
  $mlw_stat_least_popular_quiz = $wpdb->get_row( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE deleted=0 ORDER BY quiz_taken ASC LIMIT 1" );
99
  ?>
100
  <style>
@@ -166,15 +165,14 @@ function qmn_snapshot_dashboard_widget() {
166
  <li class="qmn_dashboard_element qmn_full_width">
167
  <div class="qmn_dashboard_inside">
168
  <strong><?php echo esc_html( $mlw_qmn_today_taken ); ?></strong>
169
- <?php esc_html_e('quizzes taken today', 'quiz-master-next'); ?>
170
  <span class="qmn_dashboard_graph">
171
  <?php
172
- echo esc_html( $mlw_qmn_analyze_today."% " );
173
  if ( $mlw_qmn_analyze_today >= 0 ) {
174
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/green_triangle.png'/>";
175
- }
176
- else {
177
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/red_triangle.png'/>";
178
  }
179
  ?>
180
  </span>
@@ -183,15 +181,14 @@ function qmn_snapshot_dashboard_widget() {
183
  <li class="qmn_dashboard_element qmn_full_width">
184
  <div class="qmn_dashboard_inside">
185
  <strong><?php echo esc_html( $mlw_qmn_this_week_taken ); ?></strong>
186
- <?php esc_html_e('quizzes taken last 7 days', 'quiz-master-next'); ?>
187
  <span class="qmn_dashboard_graph">
188
  <?php
189
- echo esc_html( $mlw_qmn_analyze_week."% " );
190
  if ( $mlw_qmn_analyze_week >= 0 ) {
191
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/green_triangle.png'/>";
192
- }
193
- else {
194
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/red_triangle.png'/>";
195
  }
196
  ?>
197
  </span>
@@ -200,15 +197,14 @@ function qmn_snapshot_dashboard_widget() {
200
  <li class="qmn_dashboard_element qmn_full_width">
201
  <div class="qmn_dashboard_inside">
202
  <strong><?php echo esc_html( $mlw_qmn_this_month_taken ); ?></strong>
203
- <?php esc_html_e('quizzes taken last 30 days', 'quiz-master-next'); ?>
204
  <span class="qmn_dashboard_graph">
205
  <?php
206
- echo esc_html( $mlw_qmn_analyze_month."% " );
207
  if ( $mlw_qmn_analyze_month >= 0 ) {
208
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/green_triangle.png'/>";
209
- }
210
- else {
211
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/red_triangle.png'/>";
212
  }
213
  ?>
214
  </span>
@@ -217,15 +213,14 @@ function qmn_snapshot_dashboard_widget() {
217
  <li class="qmn_dashboard_element qmn_full_width">
218
  <div class="qmn_dashboard_inside">
219
  <strong><?php echo esc_html( $mlw_qmn_this_quater_taken ); ?></strong>
220
- <?php esc_html_e('quizzes taken last 120 days', 'quiz-master-next'); ?>
221
  <span class="qmn_dashboard_graph">
222
  <?php
223
- echo esc_html( $mlw_qmn_analyze_quater."% " );
224
  if ( $mlw_qmn_analyze_quater >= 0 ) {
225
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/green_triangle.png'/>";
226
- }
227
- else {
228
- echo "<img src='".esc_url(plugin_dir_url( __FILE__ ))."../images/red_triangle.png'/>";
229
  }
230
  ?>
231
  </span>
@@ -234,25 +229,37 @@ function qmn_snapshot_dashboard_widget() {
234
  <li class="qmn_dashboard_element qmn_half_width">
235
  <div class="qmn_dashboard_inside">
236
  <strong><?php echo esc_html( $mlw_stat_total_active_quiz ); ?></strong>
237
- <?php esc_html_e('total active quizzes', 'quiz-master-next'); ?>
238
  </div>
239
  </li>
240
  <li class="qmn_dashboard_element qmn_half_width">
241
  <div class="qmn_dashboard_inside">
242
  <strong><?php echo esc_html( $mlw_stat_total_questions ); ?></strong>
243
- <?php esc_html_e('total active questions', 'quiz-master-next'); ?>
244
  </div>
245
  </li>
246
  <li class="qmn_dashboard_element qmn_half_width">
247
  <div class="qmn_dashboard_inside">
248
- <strong><?php if ( ! is_null($mlw_stat_most_popular_quiz) ) { echo wp_kses_post( $mlw_stat_most_popular_quiz->quiz_name); } ?></strong>
249
- <?php esc_html_e('most popular quiz', 'quiz-master-next'); ?>
 
 
 
 
 
 
250
  </div>
251
  </li>
252
  <li class="qmn_dashboard_element qmn_half_width">
253
  <div class="qmn_dashboard_inside">
254
- <strong><?php if ( ! is_null($mlw_stat_least_popular_quiz) ) { echo wp_kses_post( $mlw_stat_least_popular_quiz->quiz_name ); } ?></strong>
255
- <?php esc_html_e('least popular quiz', 'quiz-master-next'); ?>
 
 
 
 
 
 
256
  </div>
257
  </li>
258
  </ul>
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
 
6
  /**
7
+ * This function adds a widget to the dashboard in WordPress.
8
+ *
9
+ * @return void
10
+ * @since 4.4.0
11
+ */
12
  function qmn_add_dashboard_widget() {
13
  if ( current_user_can( 'publish_posts' ) ) {
14
  wp_add_dashboard_widget(
15
  'qmn_snapshot_widget',
16
+ __( 'Quiz And Survey Master Snapshot', 'quiz-master-next' ),
17
  'qmn_snapshot_dashboard_widget'
18
  );
19
  }
22
  add_action( 'wp_dashboard_setup', 'qmn_add_dashboard_widget' );
23
 
24
  /**
25
+ * This function creates the actual widget that is added to the dashboard.
26
+ *
27
+ * This widget adds things like the most popular/least popular quiz. How many people have taken the quiz etc.
28
+ *
29
+ * @param type description
30
+ * @return type description
31
+ * @since 4.4.0
32
+ */
33
  function qmn_snapshot_dashboard_widget() {
34
  global $wpdb;
35
+ $mlw_qmn_today_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", gmdate( 'Y-m-d', current_time( 'timestamp' ) ), gmdate( 'Y-m-d', current_time( 'timestamp' ) ) ) );
36
+ $mlw_last_week = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 7, gmdate( 'Y' ) );
37
+ $mlw_last_week = gmdate( 'Y-m-d', $mlw_last_week );
38
  $mlw_qmn_last_weekday_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_week, $mlw_last_week ) );
39
  if ( 0 != intval( $mlw_qmn_last_weekday_taken ) ) {
40
+ $mlw_qmn_analyze_today = round( ( ( $mlw_qmn_today_taken - $mlw_qmn_last_weekday_taken ) / $mlw_qmn_last_weekday_taken ) * 100, 2 );
41
+ } else {
 
42
  $mlw_qmn_analyze_today = $mlw_qmn_today_taken * 100;
43
  }
44
 
45
+ $mlw_this_week = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 6, gmdate( 'Y' ) );
46
+ $mlw_this_week = gmdate( 'Y-m-d', $mlw_this_week );
47
+ $mlw_qmn_this_week_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_this_week, gmdate( 'Y-m-d' ) ) );
48
 
49
+ $mlw_last_week_start = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 13, gmdate( 'Y' ) );
50
+ $mlw_last_week_start = gmdate( 'Y-m-d', $mlw_last_week_start );
51
+ $mlw_last_week_end = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 7, gmdate( 'Y' ) );
52
+ $mlw_last_week_end = gmdate( 'Y-m-d', $mlw_last_week_end );
53
  $mlw_qmn_last_week_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_week_start, $mlw_last_week_end ) );
54
 
55
  if ( 0 !== intval( $mlw_qmn_last_week_taken ) ) {
56
+ $mlw_qmn_analyze_week = round( ( ( $mlw_qmn_this_week_taken - $mlw_qmn_last_week_taken ) / $mlw_qmn_last_week_taken ) * 100, 2 );
57
+ } else {
 
58
  $mlw_qmn_analyze_week = $mlw_qmn_this_week_taken * 100;
59
  }
60
 
61
+ $mlw_this_month = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 29, gmdate( 'Y' ) );
62
+ $mlw_this_month = gmdate( 'Y-m-d', $mlw_this_month );
63
+ $mlw_qmn_this_month_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_this_month, gmdate( 'Y-m-d' ) ) );
64
 
65
+ $mlw_last_month_start = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 59, gmdate( 'Y' ) );
66
+ $mlw_last_month_start = gmdate( 'Y-m-d', $mlw_last_month_start );
67
+ $mlw_last_month_end = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 30, gmdate( 'Y' ) );
68
+ $mlw_last_month_end = gmdate( 'Y-m-d', $mlw_last_month_end );
69
  $mlw_qmn_last_month_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_month_start, $mlw_last_month_end ) );
70
 
71
  if ( 0 != intval( $mlw_qmn_last_month_taken ) ) {
72
+ $mlw_qmn_analyze_month = round( ( ( $mlw_qmn_this_month_taken - $mlw_qmn_last_month_taken ) / $mlw_qmn_last_month_taken ) * 100, 2 );
73
+ } else {
 
74
  $mlw_qmn_analyze_month = $mlw_qmn_this_month_taken * 100;
75
  }
76
 
77
+ $mlw_this_quater = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 89, gmdate( 'Y' ) );
78
+ $mlw_this_quater = gmdate( 'Y-m-d', $mlw_this_quater );
79
+ $mlw_qmn_this_quater_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_this_quater, gmdate( 'Y-m-d' ) ) );
80
 
81
+ $mlw_last_quater_start = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 179, gmdate( 'Y' ) );
82
+ $mlw_last_quater_start = gmdate( 'Y-m-d', $mlw_last_quater_start );
83
+ $mlw_last_quater_end = mktime( 0, 0, 0, gmdate( 'm' ), gmdate( 'd' ) - 90, gmdate( 'Y' ) );
84
+ $mlw_last_quater_end = gmdate( 'Y-m-d', $mlw_last_quater_end );
85
  $mlw_qmn_last_quater_taken = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE (time_taken_real BETWEEN '%1s 00:00:00' AND '%2s 23:59:59') AND deleted=0", $mlw_last_quater_start, $mlw_last_quater_end ) );
86
 
87
  if ( 0 != intval( $mlw_qmn_last_quater_taken ) ) {
88
+ $mlw_qmn_analyze_quater = round( ( ( $mlw_qmn_this_quater_taken - $mlw_qmn_last_quater_taken ) / $mlw_qmn_last_quater_taken ) * 100, 2 );
89
+ } else {
 
90
  $mlw_qmn_analyze_quater = $mlw_qmn_this_quater_taken * 100;
91
  }
92
 
93
  $mlw_stat_total_active_quiz = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_quizzes WHERE deleted=0 LIMIT 1" );
94
+ $mlw_stat_total_questions = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_questions WHERE deleted=0 LIMIT 1" );
95
 
96
+ $mlw_stat_most_popular_quiz = $wpdb->get_row( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE deleted=0 ORDER BY quiz_taken Desc LIMIT 1" );
97
  $mlw_stat_least_popular_quiz = $wpdb->get_row( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE deleted=0 ORDER BY quiz_taken ASC LIMIT 1" );
98
  ?>
99
  <style>
165
  <li class="qmn_dashboard_element qmn_full_width">
166
  <div class="qmn_dashboard_inside">
167
  <strong><?php echo esc_html( $mlw_qmn_today_taken ); ?></strong>
168
+ <?php esc_html_e( 'quizzes taken today', 'quiz-master-next' ); ?>
169
  <span class="qmn_dashboard_graph">
170
  <?php
171
+ echo esc_html( $mlw_qmn_analyze_today . '% ' );
172
  if ( $mlw_qmn_analyze_today >= 0 ) {
173
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/green_triangle.png'/>";
174
+ } else {
175
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/red_triangle.png'/>";
 
176
  }
177
  ?>
178
  </span>
181
  <li class="qmn_dashboard_element qmn_full_width">
182
  <div class="qmn_dashboard_inside">
183
  <strong><?php echo esc_html( $mlw_qmn_this_week_taken ); ?></strong>
184
+ <?php esc_html_e( 'quizzes taken last 7 days', 'quiz-master-next' ); ?>
185
  <span class="qmn_dashboard_graph">
186
  <?php
187
+ echo esc_html( $mlw_qmn_analyze_week . '% ' );
188
  if ( $mlw_qmn_analyze_week >= 0 ) {
189
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/green_triangle.png'/>";
190
+ } else {
191
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/red_triangle.png'/>";
 
192
  }
193
  ?>
194
  </span>
197
  <li class="qmn_dashboard_element qmn_full_width">
198
  <div class="qmn_dashboard_inside">
199
  <strong><?php echo esc_html( $mlw_qmn_this_month_taken ); ?></strong>
200
+ <?php esc_html_e( 'quizzes taken last 30 days', 'quiz-master-next' ); ?>
201
  <span class="qmn_dashboard_graph">
202
  <?php
203
+ echo esc_html( $mlw_qmn_analyze_month . '% ' );
204
  if ( $mlw_qmn_analyze_month >= 0 ) {
205
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/green_triangle.png'/>";
206
+ } else {
207
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/red_triangle.png'/>";
 
208
  }
209
  ?>
210
  </span>
213
  <li class="qmn_dashboard_element qmn_full_width">
214
  <div class="qmn_dashboard_inside">
215
  <strong><?php echo esc_html( $mlw_qmn_this_quater_taken ); ?></strong>
216
+ <?php esc_html_e( 'quizzes taken last 120 days', 'quiz-master-next' ); ?>
217
  <span class="qmn_dashboard_graph">
218
  <?php
219
+ echo esc_html( $mlw_qmn_analyze_quater . '% ' );
220
  if ( $mlw_qmn_analyze_quater >= 0 ) {
221
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/green_triangle.png'/>";
222
+ } else {
223
+ echo "<img src='" . esc_url( plugin_dir_url( __FILE__ ) ) . "../images/red_triangle.png'/>";
 
224
  }
225
  ?>
226
  </span>
229
  <li class="qmn_dashboard_element qmn_half_width">
230
  <div class="qmn_dashboard_inside">
231
  <strong><?php echo esc_html( $mlw_stat_total_active_quiz ); ?></strong>
232
+ <?php esc_html_e( 'total active quizzes', 'quiz-master-next' ); ?>
233
  </div>
234
  </li>
235
  <li class="qmn_dashboard_element qmn_half_width">
236
  <div class="qmn_dashboard_inside">
237
  <strong><?php echo esc_html( $mlw_stat_total_questions ); ?></strong>
238
+ <?php esc_html_e( 'total active questions', 'quiz-master-next' ); ?>
239
  </div>
240
  </li>
241
  <li class="qmn_dashboard_element qmn_half_width">
242
  <div class="qmn_dashboard_inside">
243
+ <strong>
244
+ <?php
245
+ if ( ! is_null( $mlw_stat_most_popular_quiz ) ) {
246
+ echo wp_kses_post( $mlw_stat_most_popular_quiz->quiz_name );
247
+ }
248
+ ?>
249
+ </strong>
250
+ <?php esc_html_e( 'most popular quiz', 'quiz-master-next' ); ?>
251
  </div>
252
  </li>
253
  <li class="qmn_dashboard_element qmn_half_width">
254
  <div class="qmn_dashboard_inside">
255
+ <strong>
256
+ <?php
257
+ if ( ! is_null( $mlw_stat_least_popular_quiz ) ) {
258
+ echo wp_kses_post( $mlw_stat_least_popular_quiz->quiz_name );
259
+ }
260
+ ?>
261
+ </strong>
262
+ <?php esc_html_e( 'least popular quiz', 'quiz-master-next' ); ?>
263
  </div>
264
  </li>
265
  </ul>
php/admin/functions.php CHANGED
@@ -21,7 +21,7 @@ add_action( 'qmn_quiz_created', 'qsm_redirect_to_edit_page', 10, 1 );
21
  function qsm_redirect_to_edit_page( $quiz_id ) {
22
  link_featured_image( $quiz_id );
23
  $url = admin_url( 'admin.php?page=mlw_quiz_options&&quiz_id=' . $quiz_id );
24
- wp_safe_redirect($url);
25
  }
26
 
27
  /**
@@ -43,7 +43,7 @@ add_action( 'admin_init', 'qsm_add_author_column_in_db' );
43
  * Insert new column in quiz table
44
  */
45
  function qsm_add_author_column_in_db() {
46
- if ( 1 !== intval ( get_option( 'qsm_update_db_column', '' ) ) ) {
47
 
48
  global $wpdb;
49
 
@@ -164,6 +164,49 @@ function qsm_add_author_column_in_db() {
164
  $inc_val = $total_count_val + 1;
165
  update_option( 'qsm_add_new_column_question_table_table', $inc_val );
166
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  }
168
 
169
  add_action( 'admin_init', 'qsm_change_the_post_type' );
@@ -172,7 +215,7 @@ add_action( 'admin_init', 'qsm_change_the_post_type' );
172
  * Transfer all quiz post to new cpt 'qsm_quiz'
173
  */
174
  function qsm_change_the_post_type() {
175
- if ( 1 !== intval (get_option( 'qsm_change_the_post_type', '' ) ) ) {
176
  $post_arr = array(
177
  'post_type' => 'quiz',
178
  'posts_per_page' => -1,
@@ -228,74 +271,74 @@ function qsm_display_question_option( $key, $single_option ) {
228
  switch ( $type ) {
229
  case 'text':
230
  ?>
231
- <div id="<?php echo esc_attr($key); ?>_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
232
  <label>
233
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
234
- <?php echo wp_kses_post( $tooltip ); ?>
235
- <?php echo wp_kses_post( $document_text ); ?>
236
  </label>
237
- <input type="text" name="<?php echo esc_attr($key); ?>" value="<?php echo isset( $single_option['default'] ) ? esc_html($single_option['default']) : ''; ?>" id="<?php echo esc_attr($key); ?>" />
238
  </div>
239
- <?php
240
  break;
241
 
242
  case 'number':
243
  ?>
244
- <div id="<?php echo esc_attr($key); ?>_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
245
  <label>
246
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
247
- <?php echo wp_kses_post( $tooltip ); ?>
248
- <?php echo wp_kses_post( $document_text ); ?>
249
  </label>
250
- <input type="number" name="<?php echo esc_attr($key); ?>" value="<?php echo isset( $single_option['default'] ) ? esc_html($single_option['default']) : ''; ?>" id="<?php echo esc_attr($key); ?>" />
251
  </div>
252
- <?php
253
  break;
254
 
255
  case 'select':
256
  ?>
257
- <div id="<?php echo esc_attr($key); ?>_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
258
  <label>
259
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
260
- <?php echo wp_kses_post( $tooltip ); ?>
261
- <?php echo wp_kses_post( $document_text ); ?>
262
  </label>
263
- <select name="<?php echo esc_attr($key); ?>" id="<?php echo esc_attr($key); ?>">
264
- <?php
265
  $default = isset( $single_option['default'] ) ? $single_option['default'] : '';
266
  if ( isset( $single_option['options'] ) && is_array( $single_option['options'] ) ) {
267
  foreach ( $single_option['options'] as $okey => $value ) {
268
  ?>
269
- <option value="<?php echo esc_attr($okey); ?>" <?php echo ($okey === $default) ? 'selected="selected"' : ''; ?>><?php echo esc_attr($value); ?></option>
270
- <?php
271
  }
272
  }
273
  ?>
274
  </select>
275
  </div>
276
- <?php
277
  break;
278
 
279
  case 'textarea':
280
  ?>
281
- <div id="<?php echo esc_attr($key); ?>_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
282
  <label>
283
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
284
- <?php echo wp_kses_post( $tooltip ); ?>
285
- <?php echo wp_kses_post( $document_text ); ?>
286
  </label>
287
- <textarea id="<?php echo esc_attr($key); ?>" name="<?php echo esc_attr($key); ?>"><?php echo isset( $single_option['default'] ) ? esc_html($single_option['default']) : ''; ?></textarea>
288
  </div>
289
- <?php
290
  break;
291
 
292
  case 'category':
293
  ?>
294
- <div id="category_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
295
  <label>
296
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
297
- <?php echo wp_kses_post( $tooltip ); ?>
298
- <?php echo wp_kses_post( $document_text ); ?>
299
  </label>
300
  <div id="categories">
301
  <a id="qsm-category-add-toggle" class="hide-if-no-js">
@@ -308,16 +351,16 @@ function qsm_display_question_option( $key, $single_option ) {
308
  </p>
309
  </div>
310
  </div>
311
- <?php
312
  break;
313
 
314
  case 'multi_category':
315
  ?>
316
- <div id="multi_category_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
317
  <label>
318
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
319
- <?php echo wp_kses_post( $tooltip ); ?>
320
- <?php echo wp_kses_post( $document_text ); ?>
321
  </label>
322
  <div id="multi_categories_wrapper" class="categorydiv">
323
  <input type='text' class='qsm-category-filter' placeholder=' <?php esc_html_e( ' Search', 'quiz-master-next' ); ?> '>
@@ -339,54 +382,54 @@ function qsm_display_question_option( $key, $single_option ) {
339
  </a>
340
  </div>
341
  </div>
342
- <?php
343
  break;
344
 
345
  case 'multi_checkbox':
346
  ?>
347
- <div id="<?php echo esc_attr($key); ?>_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
348
  <label>
349
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
350
- <?php echo wp_kses_post( $tooltip ); ?>
351
- <?php echo wp_kses_post( $document_text ); ?>
352
  </label>
353
- <?php
354
  $parent_key = $key;
355
  $default = isset( $single_option['default'] ) ? $single_option['default'] : '';
356
  if ( isset( $single_option['options'] ) && is_array( $single_option['options'] ) ) {
357
  foreach ( $single_option['options'] as $key => $value ) {
358
  ?>
359
- <input name="<?php echo esc_attr( $parent_key ); ?>[]" type="checkbox" value="<?php echo esc_attr( $key ); ?>" <?php echo ($key === $default) ? 'checked' : ''; ?> />
360
  <?php echo esc_attr( $value ); ?><br />
361
  <?php
362
  }
363
  }
364
  ?>
365
  </div>
366
- <?php
367
  break;
368
 
369
  case 'single_checkbox':
370
  ?>
371
- <div id="<?php echo esc_attr($key); ?>_area" class="qsm-row <?php echo esc_attr($show_class); ?>">
372
  <label>
373
- <?php
374
  $parent_key = $key;
375
  $default = isset( $single_option['default'] ) ? $single_option['default'] : '';
376
  if ( isset( $single_option['options'] ) && is_array( $single_option['options'] ) ) {
377
  foreach ( $single_option['options'] as $key => $value ) {
378
  ?>
379
- <input name="<?php echo esc_attr($parent_key); ?>" id="<?php echo esc_attr($parent_key); ?>" type="checkbox"value="<?php echo esc_attr($key); ?>" <?php echo ($key === $default) ? 'checked' : ''; ?> />
380
  <?php
381
  }
382
  }
383
  ?>
384
- <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
385
- <?php echo wp_kses_post( $tooltip ); ?>
386
- <?php echo wp_kses_post( $document_text ); ?>
387
  </label>
388
  </div>
389
- <?php
390
  break;
391
 
392
  default:
@@ -578,14 +621,14 @@ function qsm_create_new_quiz_wizard() {
578
  foreach ( $popular_addons as $key => $single_arr ) {
579
  ?>
580
  <div>
581
- <a href="<?php echo esc_url($single_arr['link']); ?>?utm_source=wizard&utm_medium=plugin&utm_content=all-addons-top&utm_campaign=qsm_plugin"
582
  target="_blank" rel="noopener">
583
  <span class="addon-itd-wrap">
584
- <img alt="" src="<?php echo esc_url($single_arr['img']); ?>" />
585
  </span>
586
  </a>
587
  <a class="addon-get-link"
588
- href="<?php echo esc_url($single_arr['link']); ?>?utm_source=wizard&utm_medium=plugin&utm_content=all-addons-top&utm_campaign=qsm_plugin"
589
  target="_blank" rel="noopener">
590
  <?php
591
  esc_html_e( 'Buy now', 'quiz-master-next' );
@@ -594,7 +637,7 @@ function qsm_create_new_quiz_wizard() {
594
  ?>
595
  </a>
596
  </div>
597
- <?php
598
  }
599
  }
600
  ?>
@@ -629,7 +672,7 @@ function qsm_create_new_quiz_wizard() {
629
  </div>
630
  </div>
631
  </div>
632
- <?php
633
  }
634
 
635
  /**
@@ -670,7 +713,7 @@ function qsm_text_template_variable_list() {
670
  '%RESULT_LINK%' => __( 'The link of the result page.', 'quiz-master-next' ),
671
  '%CONTACT_X%' => __( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ),
672
  '%CONTACT_ALL%' => __( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ),
673
- '%AVERAGE_CATEGORY_POINTS_X%' => __( 'X: Category name - The average amount of points a specific category earned.', 'quiz-master-next'),
674
  '%QUESTION_ANSWER_X%' => __( 'X = Question ID. It will show result of particular question.', 'quiz-master-next' ),
675
  ),
676
  );
@@ -714,7 +757,7 @@ function qsm_update_question_type_col_val() {
714
  */
715
  function qsm_check_create_tables() {
716
  global $wpdb;
717
- $install = false;
718
 
719
  $quiz_table_name = $wpdb->prefix . 'mlw_quizzes';
720
  if ( $wpdb->get_var( "SHOW TABLES LIKE '$quiz_table_name'" ) !== $quiz_table_name ) {
@@ -795,8 +838,8 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) {
795
  </div>
796
  </div>
797
  </div>
798
- <?php do_action( 'qsm_add_after_default_theme' ); ?>
799
- <?php
800
  if ( $theme_folders ) {
801
  foreach ( $theme_folders as $key => $theme ) {
802
  $theme_name = $theme['theme'];
@@ -810,7 +853,7 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) {
810
  ?>
811
  ">
812
  <input style="display: none" type="radio" name="quiz_theme_id" value="<?php echo intval( $theme_id ); ?>"
813
- <?php checked( $saved_quiz_theme, $theme_id, true ); ?>>
814
  <div class="theme-screenshot" id="qsm-theme-screenshot">
815
  <img alt="" src="<?php echo esc_url( $folder_slug . $theme_name . '/screenshot.png' ); ?>" />
816
  <div class="downloaded-theme-button">
@@ -825,11 +868,11 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) {
825
  if ( $saved_quiz_theme != $theme_id ) {
826
  if ( 'wizard_theme_list' === $wizard_theme_list ) {
827
  ?>
828
- <?php
829
  } else {
830
  ?>
831
  <button class="button qsm-activate-theme"><?php esc_html_e( 'Activate', 'quiz-master-next' ); ?></button>
832
- <?php
833
  }
834
  ?>
835
  <?php } ?>
@@ -840,7 +883,7 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) {
840
  </div>
841
  </div>
842
  </div>
843
- <?php
844
  do_action( 'qsm_add_after_themes' );
845
  }
846
  }
@@ -904,7 +947,7 @@ function qsm_get_default_wizard_themes() {
904
  <h2 class="theme-name" id="emarket-name"><?php echo esc_attr( $theme_name ); ?></h2>
905
  </div>
906
  </div>
907
- <?php
908
  }
909
  }
910
  }
@@ -955,5 +998,5 @@ function qsm_sanitize_rec_array( $array, $textarea = false ) {
955
  $array[ $key ] = $textarea ? sanitize_textarea_field( $value ) : sanitize_text_field( $value );
956
  }
957
  }
958
- return $array;
959
  }
21
  function qsm_redirect_to_edit_page( $quiz_id ) {
22
  link_featured_image( $quiz_id );
23
  $url = admin_url( 'admin.php?page=mlw_quiz_options&&quiz_id=' . $quiz_id );
24
+ wp_safe_redirect( $url );
25
  }
26
 
27
  /**
43
  * Insert new column in quiz table
44
  */
45
  function qsm_add_author_column_in_db() {
46
+ if ( 1 !== intval( get_option( 'qsm_update_db_column', '' ) ) ) {
47
 
48
  global $wpdb;
49
 
164
  $inc_val = $total_count_val + 1;
165
  update_option( 'qsm_add_new_column_question_table_table', $inc_val );
166
  }
167
+ /**
168
+ * Add new column in the results table
169
+ *
170
+ * @since 7.3.7
171
+ */
172
+ if ( get_option( 'qsm_update_result_db_column_page_url', '' ) != '1' ) {
173
+ global $wpdb;
174
+ $result_table_name = $wpdb->prefix . 'mlw_results';
175
+ $table_result_col_obj = $wpdb->get_results(
176
+ $wpdb->prepare(
177
+ 'SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ',
178
+ $wpdb->dbname,
179
+ $result_table_name,
180
+ 'page_url'
181
+ )
182
+ );
183
+ if ( empty( $table_result_col_obj ) ) {
184
+ $wpdb->query( "ALTER TABLE $result_table_name ADD page_url varchar(255) NOT NULL" );
185
+ }
186
+ update_option( 'qsm_update_result_db_column_page_url', '1' );
187
+ }
188
+
189
+ /**
190
+ * Add new column in the results table
191
+ *
192
+ * @since 7.3.7
193
+ */
194
+ if ( get_option( 'qsm_update_result_db_column_page_name', '' ) != '1' ) {
195
+ global $wpdb;
196
+ $result_table_name = $wpdb->prefix . 'mlw_results';
197
+ $table_result_col_obj = $wpdb->get_results(
198
+ $wpdb->prepare(
199
+ 'SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ',
200
+ $wpdb->dbname,
201
+ $result_table_name,
202
+ 'page_name'
203
+ )
204
+ );
205
+ if ( empty( $table_result_col_obj ) ) {
206
+ $wpdb->query( "ALTER TABLE $result_table_name ADD page_name varchar(255) NOT NULL" );
207
+ }
208
+ update_option( 'qsm_update_result_db_column_page_name', '1' );
209
+ }
210
  }
211
 
212
  add_action( 'admin_init', 'qsm_change_the_post_type' );
215
  * Transfer all quiz post to new cpt 'qsm_quiz'
216
  */
217
  function qsm_change_the_post_type() {
218
+ if ( 1 !== intval( get_option( 'qsm_change_the_post_type', '' ) ) ) {
219
  $post_arr = array(
220
  'post_type' => 'quiz',
221
  'posts_per_page' => -1,
271
  switch ( $type ) {
272
  case 'text':
273
  ?>
274
+ <div id="<?php echo esc_attr( $key ); ?>_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
275
  <label>
276
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
277
+ <?php echo wp_kses_post( $tooltip ); ?>
278
+ <?php echo wp_kses_post( $document_text ); ?>
279
  </label>
280
+ <input type="text" name="<?php echo esc_attr( $key ); ?>" value="<?php echo isset( $single_option['default'] ) ? esc_html( $single_option['default'] ) : ''; ?>" id="<?php echo esc_attr( $key ); ?>" />
281
  </div>
282
+ <?php
283
  break;
284
 
285
  case 'number':
286
  ?>
287
+ <div id="<?php echo esc_attr( $key ); ?>_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
288
  <label>
289
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
290
+ <?php echo wp_kses_post( $tooltip ); ?>
291
+ <?php echo wp_kses_post( $document_text ); ?>
292
  </label>
293
+ <input type="number" name="<?php echo esc_attr( $key ); ?>" value="<?php echo isset( $single_option['default'] ) ? esc_html( $single_option['default'] ) : ''; ?>" id="<?php echo esc_attr( $key ); ?>" />
294
  </div>
295
+ <?php
296
  break;
297
 
298
  case 'select':
299
  ?>
300
+ <div id="<?php echo esc_attr( $key ); ?>_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
301
  <label>
302
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
303
+ <?php echo wp_kses_post( $tooltip ); ?>
304
+ <?php echo wp_kses_post( $document_text ); ?>
305
  </label>
306
+ <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>">
307
+ <?php
308
  $default = isset( $single_option['default'] ) ? $single_option['default'] : '';
309
  if ( isset( $single_option['options'] ) && is_array( $single_option['options'] ) ) {
310
  foreach ( $single_option['options'] as $okey => $value ) {
311
  ?>
312
+ <option value="<?php echo esc_attr( $okey ); ?>" <?php echo ( $okey === $default ) ? 'selected="selected"' : ''; ?>><?php echo esc_attr( $value ); ?></option>
313
+ <?php
314
  }
315
  }
316
  ?>
317
  </select>
318
  </div>
319
+ <?php
320
  break;
321
 
322
  case 'textarea':
323
  ?>
324
+ <div id="<?php echo esc_attr( $key ); ?>_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
325
  <label>
326
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
327
+ <?php echo wp_kses_post( $tooltip ); ?>
328
+ <?php echo wp_kses_post( $document_text ); ?>
329
  </label>
330
+ <textarea id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>"><?php echo isset( $single_option['default'] ) ? esc_html( $single_option['default'] ) : ''; ?></textarea>
331
  </div>
332
+ <?php
333
  break;
334
 
335
  case 'category':
336
  ?>
337
+ <div id="category_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
338
  <label>
339
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
340
+ <?php echo wp_kses_post( $tooltip ); ?>
341
+ <?php echo wp_kses_post( $document_text ); ?>
342
  </label>
343
  <div id="categories">
344
  <a id="qsm-category-add-toggle" class="hide-if-no-js">
351
  </p>
352
  </div>
353
  </div>
354
+ <?php
355
  break;
356
 
357
  case 'multi_category':
358
  ?>
359
+ <div id="multi_category_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
360
  <label>
361
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
362
+ <?php echo wp_kses_post( $tooltip ); ?>
363
+ <?php echo wp_kses_post( $document_text ); ?>
364
  </label>
365
  <div id="multi_categories_wrapper" class="categorydiv">
366
  <input type='text' class='qsm-category-filter' placeholder=' <?php esc_html_e( ' Search', 'quiz-master-next' ); ?> '>
382
  </a>
383
  </div>
384
  </div>
385
+ <?php
386
  break;
387
 
388
  case 'multi_checkbox':
389
  ?>
390
+ <div id="<?php echo esc_attr( $key ); ?>_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
391
  <label>
392
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
393
+ <?php echo wp_kses_post( $tooltip ); ?>
394
+ <?php echo wp_kses_post( $document_text ); ?>
395
  </label>
396
+ <?php
397
  $parent_key = $key;
398
  $default = isset( $single_option['default'] ) ? $single_option['default'] : '';
399
  if ( isset( $single_option['options'] ) && is_array( $single_option['options'] ) ) {
400
  foreach ( $single_option['options'] as $key => $value ) {
401
  ?>
402
+ <input name="<?php echo esc_attr( $parent_key ); ?>[]" type="checkbox" value="<?php echo esc_attr( $key ); ?>" <?php echo ( $key === $default ) ? 'checked' : ''; ?> />
403
  <?php echo esc_attr( $value ); ?><br />
404
  <?php
405
  }
406
  }
407
  ?>
408
  </div>
409
+ <?php
410
  break;
411
 
412
  case 'single_checkbox':
413
  ?>
414
+ <div id="<?php echo esc_attr( $key ); ?>_area" class="qsm-row <?php echo esc_attr( $show_class ); ?>">
415
  <label>
416
+ <?php
417
  $parent_key = $key;
418
  $default = isset( $single_option['default'] ) ? $single_option['default'] : '';
419
  if ( isset( $single_option['options'] ) && is_array( $single_option['options'] ) ) {
420
  foreach ( $single_option['options'] as $key => $value ) {
421
  ?>
422
+ <input name="<?php echo esc_attr( $parent_key ); ?>" id="<?php echo esc_attr( $parent_key ); ?>" type="checkbox"value="<?php echo esc_attr( $key ); ?>" <?php echo ( $key === $default ) ? 'checked' : ''; ?> />
423
  <?php
424
  }
425
  }
426
  ?>
427
+ <?php echo isset( $single_option['label'] ) ? wp_kses_post( $single_option['label'] ) : ''; ?>
428
+ <?php echo wp_kses_post( $tooltip ); ?>
429
+ <?php echo wp_kses_post( $document_text ); ?>
430
  </label>
431
  </div>
432
+ <?php
433
  break;
434
 
435
  default:
621
  foreach ( $popular_addons as $key => $single_arr ) {
622
  ?>
623
  <div>
624
+ <a href="<?php echo esc_url( $single_arr['link'] ); ?>?utm_source=wizard&utm_medium=plugin&utm_content=all-addons-top&utm_campaign=qsm_plugin"
625
  target="_blank" rel="noopener">
626
  <span class="addon-itd-wrap">
627
+ <img alt="" src="<?php echo esc_url( $single_arr['img'] ); ?>" />
628
  </span>
629
  </a>
630
  <a class="addon-get-link"
631
+ href="<?php echo esc_url( $single_arr['link'] ); ?>?utm_source=wizard&utm_medium=plugin&utm_content=all-addons-top&utm_campaign=qsm_plugin"
632
  target="_blank" rel="noopener">
633
  <?php
634
  esc_html_e( 'Buy now', 'quiz-master-next' );
637
  ?>
638
  </a>
639
  </div>
640
+ <?php
641
  }
642
  }
643
  ?>
672
  </div>
673
  </div>
674
  </div>
675
+ <?php
676
  }
677
 
678
  /**
713
  '%RESULT_LINK%' => __( 'The link of the result page.', 'quiz-master-next' ),
714
  '%CONTACT_X%' => __( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ),
715
  '%CONTACT_ALL%' => __( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ),
716
+ '%AVERAGE_CATEGORY_POINTS_X%' => __( 'X: Category name - The average amount of points a specific category earned.', 'quiz-master-next' ),
717
  '%QUESTION_ANSWER_X%' => __( 'X = Question ID. It will show result of particular question.', 'quiz-master-next' ),
718
  ),
719
  );
757
  */
758
  function qsm_check_create_tables() {
759
  global $wpdb;
760
+ $install = false;
761
 
762
  $quiz_table_name = $wpdb->prefix . 'mlw_quizzes';
763
  if ( $wpdb->get_var( "SHOW TABLES LIKE '$quiz_table_name'" ) !== $quiz_table_name ) {
838
  </div>
839
  </div>
840
  </div>
841
+ <?php do_action( 'qsm_add_after_default_theme' ); ?>
842
+ <?php
843
  if ( $theme_folders ) {
844
  foreach ( $theme_folders as $key => $theme ) {
845
  $theme_name = $theme['theme'];
853
  ?>
854
  ">
855
  <input style="display: none" type="radio" name="quiz_theme_id" value="<?php echo intval( $theme_id ); ?>"
856
+ <?php checked( $saved_quiz_theme, $theme_id, true ); ?>>
857
  <div class="theme-screenshot" id="qsm-theme-screenshot">
858
  <img alt="" src="<?php echo esc_url( $folder_slug . $theme_name . '/screenshot.png' ); ?>" />
859
  <div class="downloaded-theme-button">
868
  if ( $saved_quiz_theme != $theme_id ) {
869
  if ( 'wizard_theme_list' === $wizard_theme_list ) {
870
  ?>
871
+ <?php
872
  } else {
873
  ?>
874
  <button class="button qsm-activate-theme"><?php esc_html_e( 'Activate', 'quiz-master-next' ); ?></button>
875
+ <?php
876
  }
877
  ?>
878
  <?php } ?>
883
  </div>
884
  </div>
885
  </div>
886
+ <?php
887
  do_action( 'qsm_add_after_themes' );
888
  }
889
  }
947
  <h2 class="theme-name" id="emarket-name"><?php echo esc_attr( $theme_name ); ?></h2>
948
  </div>
949
  </div>
950
+ <?php
951
  }
952
  }
953
  }
998
  $array[ $key ] = $textarea ? sanitize_textarea_field( $value ) : sanitize_text_field( $value );
999
  }
1000
  }
1001
+ return $array;
1002
  }
php/admin/options-page-contact-tab.php CHANGED
@@ -11,7 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
11
  */
12
  function qsm_settings_contact_tab() {
13
  global $mlwQuizMasterNext;
14
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( "Contact", 'quiz-master-next' ), 'qsm_options_contact_tab_content' );
15
  }
16
  add_action("plugins_loaded", 'qsm_settings_contact_tab', 5);
17
 
11
  */
12
  function qsm_settings_contact_tab() {
13
  global $mlwQuizMasterNext;
14
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( "Contact", 'quiz-master-next' ), 'qsm_options_contact_tab_content', 'contact' );
15
  }
16
  add_action("plugins_loaded", 'qsm_settings_contact_tab', 5);
17
 
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' );
21
  }
22
  add_action( 'plugins_loaded', 'qsm_settings_email_tab', 5 );
23
 
@@ -83,20 +83,28 @@ function qsm_options_emails_tab_content() {
83
  </header>
84
  <main class="qsm-popup__content" id="show-all-variable-content">
85
  <?php
86
- $variable_list = qsm_text_template_variable_list();
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
- foreach ( $variable_list as $category_name => $category_variables ) {
 
 
 
 
 
 
 
 
 
 
 
 
95
  ?>
96
- <div><h2><?php echo esc_attr($category_name);?></h2></div>
97
- <?php
98
- foreach ( $category_variables as $variable_key => $variable ) {
99
- ?>
100
  <div class="popup-template-span-wrap">
101
  <span class="qsm-text-template-span">
102
  <span class="button button-default template-variable"><?php echo esc_attr($variable_key); ?></span>
@@ -109,10 +117,11 @@ function qsm_options_emails_tab_content() {
109
  </span>
110
  </div>
111
  <?php
112
- }
113
  }
114
  }
115
- ?>
 
 
116
  </main>
117
  <footer class="qsm-popup__footer" style="text-align: right;">
118
  <button class="button button-default" data-micromodal-close=""
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
 
83
  </header>
84
  <main class="qsm-popup__content" id="show-all-variable-content">
85
  <?php
86
+ $variable_list = qsm_text_template_variable_list();
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>
117
  </span>
118
  </div>
119
  <?php
 
120
  }
121
  }
122
+ }
123
+ }
124
+ ?>
125
  </main>
126
  <footer class="qsm-popup__footer" style="text-align: right;">
127
  <button class="button button-default" data-micromodal-close=""
php/admin/options-page-option-tab.php CHANGED
@@ -11,7 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) {
11
  */
12
  function qsm_settings_options_tab() {
13
  global $mlwQuizMasterNext;
14
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Options', 'quiz-master-next' ), 'qsm_options_option_tab_content' );
15
  }
16
  add_action( 'plugins_loaded', 'qsm_settings_options_tab', 5 );
17
 
11
  */
12
  function qsm_settings_options_tab() {
13
  global $mlwQuizMasterNext;
14
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Options', 'quiz-master-next' ), 'qsm_options_option_tab_content', 'options');
15
  }
16
  add_action( 'plugins_loaded', 'qsm_settings_options_tab', 5 );
17
 
php/admin/options-page-questions-tab.php CHANGED
@@ -14,11 +14,11 @@ if ( ! defined( 'ABSPATH' ) ) {
14
  * Adds the settings for questions tab to the Quiz Settings page.
15
  *
16
  * @return void
17
- * @since 4.4.0
18
  */
19
  function qsm_settings_questions_tab() {
20
  global $mlwQuizMasterNext;
21
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Questions', 'quiz-master-next' ), 'qsm_options_questions_tab_content' );
22
  }
23
  add_action( 'plugins_loaded', 'qsm_settings_questions_tab', 5 );
24
 
@@ -26,7 +26,7 @@ add_action( 'plugins_loaded', 'qsm_settings_questions_tab', 5 );
26
  * Adds the content for the options for questions tab.
27
  *
28
  * @return void
29
- * @since 4.4.0
30
  */
31
  function qsm_options_questions_tab_content() {
32
  global $wpdb;
@@ -117,7 +117,7 @@ function qsm_options_questions_tab_content() {
117
  <p><?php esc_html_e( 'This quiz has the "How many questions per page would you like?" option enabled. The pages below will not be used while that option is enabled. To turn off, go to the "Options" tab and set that option to 0.', 'quiz-master-next' ); ?>
118
  </p>
119
  </div>
120
- <?php
121
  }
122
  $from_total = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'question_from_total' );
123
  if ( 0 != $from_total ) {
@@ -126,7 +126,7 @@ function qsm_options_questions_tab_content() {
126
  <p><?php esc_html_e( 'This quiz has the "How many questions should be loaded for quiz?" option enabled. The pages below will not be used while that option is enabled. To turn off, go to the "Options" tab and set that option to 0.', 'quiz-master-next' ); ?>
127
  </p>
128
  </div>
129
- <?php
130
  }
131
  $randomness = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'randomness_order' );
132
  if ( 0 != $randomness ) {
@@ -135,7 +135,7 @@ function qsm_options_questions_tab_content() {
135
  <p><?php esc_html_e( 'This quiz has the "Are the questions random?" option enabled. The pages below will not be used while that option is enabled. To turn off, go to the "Options" tab and set that option to "No".', 'quiz-master-next' ); ?>
136
  </p>
137
  </div>
138
- <?php
139
  }
140
  ?>
141
  <h3 style="display: none;">Questions</h3>
@@ -146,11 +146,10 @@ function qsm_options_questions_tab_content() {
146
  <span><b><?php esc_html_e( 'Total Questions:', 'quiz-master-next' ); ?></b> <span id="total-questions"></span></span>
147
  <p class="search-box">
148
  <label class="screen-reader-text" for="question_search">Search Questions:</label>
149
- <input type="search" id="question_search" name="question_search" value="">
150
- <a href="#" class="button"><?php esc_html_e( 'Search Questions', 'quiz-master-next' ); ?></a>
151
  </p>
152
  </div>
153
- <div class="questions quiz_form_type_<?php echo esc_attr($form_type); ?> quiz_quiz_systen_<?php echo esc_attr($quiz_system); ?>">
154
  <div class="qsm-showing-loader" style="text-align: center;margin-bottom: 20px;">
155
  <div class="qsm-spinner-loader"></div>
156
  </div>
@@ -158,7 +157,7 @@ function qsm_options_questions_tab_content() {
158
  <div class="question-create-page">
159
  <div>
160
  <button class="new-page-button button button-primary"><span class="dashicons dashicons-plus-alt2"></span>
161
- <?php esc_html_e( 'Create New Page', 'quiz-master-next' ); ?></button>
162
  <button style="display: none;"
163
  class="save-page-button button button-primary"><?php esc_html_e( 'Save Questions and Pages', 'quiz-master-next' ); ?></button>
164
  <span class="spinner" id="save-edit-quiz-pages" style="float: none;"></span>
@@ -259,9 +258,17 @@ function qsm_options_questions_tab_content() {
259
  // 'description' => __( 'Use points based grading system for Polar questions.', 'quiz-master-next' ),
260
  // ),
261
  );
262
-
 
 
 
 
 
 
 
 
263
  // disabling polar for form type quiz and system correct/incorrect
264
- if ( 0 === intval ( $form_type ) && 0 === intval ( $quiz_system ) ) {
265
  $polar_class = $polar_question_use = '';
266
  $description_arr[] = array(
267
  'question_type_id' => '13',
@@ -271,20 +278,27 @@ function qsm_options_questions_tab_content() {
271
  $polar_class = 'qsm_show_question_type_13';
272
  $polar_question_use = ',13';
273
  }
 
 
 
 
 
 
 
 
274
  $description_arr = apply_filters( 'qsm_question_type_description', $description_arr );
275
  if ( $description_arr ) {
276
  foreach ( $description_arr as $value ) {
277
  $question_type_id = $value['question_type_id'];
278
  ?>
279
- <p id="question_type_<?php echo esc_attr($question_type_id); ?>_description"
280
- class="question-type-description"><?php echo esc_attr($value['description']); ?></p>
281
- <?php
282
  }
283
  }
284
  ?>
285
  </div>
286
- <div id="qsm_optoins_wrapper"
287
- class="qsm-row qsm_hide_for_other qsm_show_question_type_0 qsm_show_question_type_1 qsm_show_question_type_2 qsm_show_question_type_3 qsm_show_question_type_4 qsm_show_question_type_5 qsm_show_question_type_7 qsm_show_question_type_10 qsm_show_question_type_12 qsm_show_question_type_14 <?php echo esc_attr( $polar_class ); ?>">
288
  <label class="answer-header">
289
  <?php esc_html_e( 'Answers', 'quiz-master-next' ); ?>
290
  <a class="qsm-question-doc" rel="noopener"
@@ -309,12 +323,18 @@ function qsm_options_questions_tab_content() {
309
  <?php esc_html_e( 'Add Correct Answer Info', 'quiz-master-next' ); ?></a>
310
  <div class="qsm-row" style="display: none;">
311
  <?php
 
 
 
 
 
 
312
  $answer_area_option = array(
313
  'correct_answer_info' => array(
314
  'label' => __( 'Correct Answer Info', 'quiz-master-next' ),
315
  'type' => 'textarea',
316
  'default' => '',
317
- 'show' => '0,1,2,3,4,5,7,10,12,14' . $polar_question_use,
318
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/questions-tab/#Correct-Answer-Info',
319
  ),
320
  );
@@ -348,6 +368,9 @@ function qsm_options_questions_tab_content() {
348
  <select name="question_type" id="question_type">
349
  <?php
350
  foreach ( $question_types as $type ) {
 
 
 
351
  echo '<option value="' . esc_attr( $type['slug'] ) . '">' . esc_html( $type['name'] ) . '</option>';
352
  }
353
  ?>
@@ -357,6 +380,18 @@ function qsm_options_questions_tab_content() {
357
  <p class="hidden" id="question_type_info"></p>
358
  </div>
359
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
360
  $simple_question_option = array(
361
  'change-answer-editor' => array(
362
  'label' => __( 'Answers Type', 'quiz-master-next' ),
@@ -368,7 +403,7 @@ function qsm_options_questions_tab_content() {
368
  'image' => __( 'Image Answers', 'quiz-master-next' ),
369
  ),
370
  'default' => 'text',
371
- 'show' => '0,1,2,4,13',
372
  // 'tooltip' => __('You can use text and rich answer for question answers.', 'quiz-master-next'),.
373
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/questions-tab/#Answer-Type',
374
  ),
@@ -391,7 +426,7 @@ function qsm_options_questions_tab_content() {
391
  'sequence' => __( 'Sequentially', 'quiz-master-next' ),
392
  ),
393
  'default' => 'random',
394
- 'show' => '14',
395
  ),
396
  );
397
  $simple_question_option = apply_filters( 'qsm_question_format_option', $simple_question_option );
@@ -481,6 +516,36 @@ function qsm_options_questions_tab_content() {
481
  <div class="inside">
482
  <div class="advanced-content">
483
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  $advanced_question_option = array(
485
  'comments' => array(
486
  'label' => __( 'Comment Field', 'quiz-master-next' ),
@@ -510,7 +575,7 @@ function qsm_options_questions_tab_content() {
510
  '1' => __( 'Yes', 'quiz-master-next' ),
511
  ),
512
  'default' => '0',
513
- 'show' => '3, 14',
514
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Hide-Autofill',
515
  ),
516
  'limit_text' => array(
@@ -518,7 +583,7 @@ function qsm_options_questions_tab_content() {
518
  'type' => 'text',
519
  'priority' => '7',
520
  'default' => '',
521
- 'show' => '3, 5, 7, 14',
522
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Limit-Text',
523
  ),
524
  'limit_multiple_response' => array(
@@ -526,7 +591,7 @@ function qsm_options_questions_tab_content() {
526
  'type' => 'text',
527
  'priority' => '8',
528
  'default' => '',
529
- 'show' => '4,10',
530
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Limit-Multiple-Choice',
531
  ),
532
  'file_upload_type' => array(
@@ -542,7 +607,7 @@ function qsm_options_questions_tab_content() {
542
  'video/mp4' => __( 'Video', 'quiz-master-next' ),
543
  ),
544
  'default' => 'image',
545
- 'show' => '11',
546
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Allow-File-Type',
547
  ),
548
  'file_upload_limit' => array(
@@ -550,7 +615,7 @@ function qsm_options_questions_tab_content() {
550
  'type' => 'number',
551
  'priority' => '9',
552
  'default' => '',
553
- 'show' => '11',
554
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#File-Upload-Limit',
555
  ),
556
  );
@@ -611,7 +676,7 @@ function qsm_options_questions_tab_content() {
611
  </div>
612
  </div>
613
 
614
- <?php add_action('admin_footer', 'qsm_options_questions_tab_template'); ?>
615
 
616
  <div class="qsm-popup qsm-popup-slide" id="modal-7" aria-hidden="false">
617
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close="">
@@ -724,7 +789,7 @@ function qsm_options_questions_tab_content() {
724
  </div>
725
  </div>
726
 
727
- <?php
728
  }
729
 
730
  add_action( 'wp_ajax_qsm_save_pages', 'qsm_ajax_save_pages' );
@@ -741,7 +806,7 @@ function qsm_ajax_save_pages() {
741
  }
742
 
743
  global $mlwQuizMasterNext;
744
- $json = array(
745
  'status' => 'error',
746
  );
747
 
@@ -764,7 +829,7 @@ add_action( 'wp_ajax_qsm_load_all_quiz_questions', 'qsm_load_all_quiz_questions_
764
  /**
765
  * Loads all the questions and echos out JSON
766
  *
767
- * @since 0.1.0
768
  * @return void
769
  */
770
  function qsm_load_all_quiz_questions_ajax() {
@@ -796,7 +861,7 @@ add_action( 'wp_ajax_qsm_send_data_sendy', 'qsm_send_data_sendy' );
796
  */
797
  function qsm_send_data_sendy() {
798
  if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'ajax-nonce-sendy-save' ) ) {
799
- die( 'Busted!' );
800
  }
801
 
802
  $sendy_url = 'http://sendy.expresstech.io';
@@ -931,7 +996,7 @@ function qsm_delete_question_from_database() {
931
  wp_die();
932
  }
933
  $question_id = isset( $_POST['question_id'] ) ? intval( $_POST['question_id'] ) : 0;
934
- if ( $question_id ) {
935
  global $wpdb;
936
  $wpdb->delete( $wpdb->prefix . 'mlw_questions', array( 'question_id' => $question_id ) );
937
  echo wp_json_encode(
@@ -951,10 +1016,9 @@ add_action( 'wp_ajax_qsm_delete_question_from_database', 'qsm_delete_question_fr
951
  add_action( 'wp_ajax_save_new_category', 'qsm_save_new_category' );
952
 
953
  function qsm_save_new_category() {
954
-
955
  $category = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
956
  $parent = isset( $_POST['parent'] ) ? intval( $_POST['parent'] ) : '';
957
- $parent = ( -1 == $parent) ? 0 : $parent;
958
  $term_array = wp_insert_term(
959
  $category,
960
  'qsm_category',
@@ -971,7 +1035,7 @@ function qsm_save_new_category() {
971
  *
972
  * @since 7.3.5
973
  */
974
- function qsm_options_questions_tab_template(){
975
  ?>
976
  <!-- View for Page -->
977
  <script type="text/template" id="tmpl-page">
@@ -1046,9 +1110,10 @@ function qsm_options_questions_tab_template(){
1046
  <# } else { #>
1047
  <div><input type="text" class="answer-points" value="{{data.points}}" placeholder="Points"/></div>
1048
  <# } #>
1049
- <?php do_action( 'qsm_admin_single_answer_option_fields' ); ?>
1050
  </div>
1051
  </script>
1052
  <?php
 
1053
  }
1054
  ?>
14
  * Adds the settings for questions tab to the Quiz Settings page.
15
  *
16
  * @return void
17
+ * @since 4.4.0
18
  */
19
  function qsm_settings_questions_tab() {
20
  global $mlwQuizMasterNext;
21
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Questions', 'quiz-master-next' ), 'qsm_options_questions_tab_content', 'questions' );
22
  }
23
  add_action( 'plugins_loaded', 'qsm_settings_questions_tab', 5 );
24
 
26
  * Adds the content for the options for questions tab.
27
  *
28
  * @return void
29
+ * @since 4.4.0
30
  */
31
  function qsm_options_questions_tab_content() {
32
  global $wpdb;
117
  <p><?php esc_html_e( 'This quiz has the "How many questions per page would you like?" option enabled. The pages below will not be used while that option is enabled. To turn off, go to the "Options" tab and set that option to 0.', 'quiz-master-next' ); ?>
118
  </p>
119
  </div>
120
+ <?php
121
  }
122
  $from_total = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'question_from_total' );
123
  if ( 0 != $from_total ) {
126
  <p><?php esc_html_e( 'This quiz has the "How many questions should be loaded for quiz?" option enabled. The pages below will not be used while that option is enabled. To turn off, go to the "Options" tab and set that option to 0.', 'quiz-master-next' ); ?>
127
  </p>
128
  </div>
129
+ <?php
130
  }
131
  $randomness = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'randomness_order' );
132
  if ( 0 != $randomness ) {
135
  <p><?php esc_html_e( 'This quiz has the "Are the questions random?" option enabled. The pages below will not be used while that option is enabled. To turn off, go to the "Options" tab and set that option to "No".', 'quiz-master-next' ); ?>
136
  </p>
137
  </div>
138
+ <?php
139
  }
140
  ?>
141
  <h3 style="display: none;">Questions</h3>
146
  <span><b><?php esc_html_e( 'Total Questions:', 'quiz-master-next' ); ?></b> <span id="total-questions"></span></span>
147
  <p class="search-box">
148
  <label class="screen-reader-text" for="question_search">Search Questions:</label>
149
+ <input type="search" id="question_search" name="question_search" value="" placeholder="<?php esc_html_e( 'Search Questions', 'quiz-master-next' ); ?>">
 
150
  </p>
151
  </div>
152
+ <div class="questions quiz_form_type_<?php echo esc_attr( $form_type ); ?> quiz_quiz_systen_<?php echo esc_attr( $quiz_system ); ?>">
153
  <div class="qsm-showing-loader" style="text-align: center;margin-bottom: 20px;">
154
  <div class="qsm-spinner-loader"></div>
155
  </div>
157
  <div class="question-create-page">
158
  <div>
159
  <button class="new-page-button button button-primary"><span class="dashicons dashicons-plus-alt2"></span>
160
+ <?php esc_html_e( 'Create New Page', 'quiz-master-next' ); ?></button>
161
  <button style="display: none;"
162
  class="save-page-button button button-primary"><?php esc_html_e( 'Save Questions and Pages', 'quiz-master-next' ); ?></button>
163
  <span class="spinner" id="save-edit-quiz-pages" style="float: none;"></span>
258
  // 'description' => __( 'Use points based grading system for Polar questions.', 'quiz-master-next' ),
259
  // ),
260
  );
261
+ foreach ( $question_types as $type ) {
262
+ if ( isset( $type['options']['description'] ) && null !== $type['options']['description'] ) {
263
+ $description = array(
264
+ 'question_type_id' => $type['slug'],
265
+ 'description' => $type['options']['description'],
266
+ );
267
+ array_push( $description_arr, $description );
268
+ }
269
+ }
270
  // disabling polar for form type quiz and system correct/incorrect
271
+ if ( 0 === intval( $form_type ) && 0 === intval( $quiz_system ) ) {
272
  $polar_class = $polar_question_use = '';
273
  $description_arr[] = array(
274
  'question_type_id' => '13',
278
  $polar_class = 'qsm_show_question_type_13';
279
  $polar_question_use = ',13';
280
  }
281
+
282
+ $show_answer_option = '';
283
+ foreach ( $question_types as $type ) {
284
+ if ( isset( $type['options']['show_answer_option'] ) && $type['options']['show_answer_option'] ) {
285
+ $show_answer_option .= ' qsm_show_question_type_' . $type['slug'];
286
+ }
287
+ }
288
+
289
  $description_arr = apply_filters( 'qsm_question_type_description', $description_arr );
290
  if ( $description_arr ) {
291
  foreach ( $description_arr as $value ) {
292
  $question_type_id = $value['question_type_id'];
293
  ?>
294
+ <p id="question_type_<?php echo esc_attr( $question_type_id ); ?>_description"
295
+ class="question-type-description"><?php echo esc_attr( $value['description'] ); ?></p>
296
+ <?php
297
  }
298
  }
299
  ?>
300
  </div>
301
+ <div id="qsm_optoins_wrapper" class="qsm-row qsm_hide_for_other qsm_show_question_type_0 qsm_show_question_type_1 qsm_show_question_type_2 qsm_show_question_type_3 qsm_show_question_type_4 qsm_show_question_type_5 qsm_show_question_type_7 qsm_show_question_type_10 qsm_show_question_type_12 qsm_show_question_type_14 <?php echo esc_attr( $polar_class . $show_answer_option ); ?>">
 
302
  <label class="answer-header">
303
  <?php esc_html_e( 'Answers', 'quiz-master-next' ); ?>
304
  <a class="qsm-question-doc" rel="noopener"
323
  <?php esc_html_e( 'Add Correct Answer Info', 'quiz-master-next' ); ?></a>
324
  <div class="qsm-row" style="display: none;">
325
  <?php
326
+ $show_correct_answer_info = '';
327
+ foreach ( $question_types as $type ) {
328
+ if ( isset( $type['options']['show_correct_answer_info'] ) && $type['options']['show_correct_answer_info'] ) {
329
+ $show_correct_answer_info .= ',' . $type['slug'];
330
+ }
331
+ }
332
  $answer_area_option = array(
333
  'correct_answer_info' => array(
334
  'label' => __( 'Correct Answer Info', 'quiz-master-next' ),
335
  'type' => 'textarea',
336
  'default' => '',
337
+ 'show' => '0,1,2,3,4,5,7,10,12,14' . $polar_question_use . $show_correct_answer_info,
338
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/questions-tab/#Correct-Answer-Info',
339
  ),
340
  );
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
  ?>
380
  <p class="hidden" id="question_type_info"></p>
381
  </div>
382
  <?php
383
+ $show_change_answer_editor = '';
384
+ foreach ( $question_types as $type ) {
385
+ if ( isset( $type['options']['show_change_answer_editor'] ) && $type['options']['show_change_answer_editor'] ) {
386
+ $show_change_answer_editor .= ',' . $type['slug'];
387
+ }
388
+ }
389
+ $show_match_answer = '';
390
+ foreach ( $question_types as $type ) {
391
+ if ( isset( $type['options']['show_match_answer'] ) && $type['options']['show_match_answer'] ) {
392
+ $show_match_answer .= ',' . $type['slug'];
393
+ }
394
+ }
395
  $simple_question_option = array(
396
  'change-answer-editor' => array(
397
  'label' => __( 'Answers Type', 'quiz-master-next' ),
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
  ),
426
  'sequence' => __( 'Sequentially', 'quiz-master-next' ),
427
  ),
428
  'default' => 'random',
429
+ 'show' => '14' . $show_match_answer,
430
  ),
431
  );
432
  $simple_question_option = apply_filters( 'qsm_question_format_option', $simple_question_option );
516
  <div class="inside">
517
  <div class="advanced-content">
518
  <?php
519
+ $show_autofill = '';
520
+ foreach ( $question_types as $type ) {
521
+ if ( isset( $type['options']['show_autofill'] ) && $type['options']['show_autofill'] ) {
522
+ $show_autofill .= ',' . $type['slug'];
523
+ }
524
+ }
525
+ $show_limit_text = '';
526
+ foreach ( $question_types as $type ) {
527
+ if ( isset( $type['options']['show_limit_text'] ) && $type['options']['show_limit_text'] ) {
528
+ $show_limit_text .= ',' . $type['slug'];
529
+ }
530
+ }
531
+ $show_limit_multiple_response = '';
532
+ foreach ( $question_types as $type ) {
533
+ if ( isset( $type['options']['show_limit_multiple_response'] ) && $type['options']['show_limit_multiple_response'] ) {
534
+ $show_limit_multiple_response .= ',' . $type['slug'];
535
+ }
536
+ }
537
+ $show_file_upload_type = '';
538
+ foreach ( $question_types as $type ) {
539
+ if ( isset( $type['options']['show_file_upload_type'] ) && $type['options']['show_file_upload_type'] ) {
540
+ $show_file_upload_type .= ',' . $type['slug'];
541
+ }
542
+ }
543
+ $show_file_upload_limit = '';
544
+ foreach ( $question_types as $type ) {
545
+ if ( isset( $type['options']['show_file_upload_limit'] ) && $type['options']['show_file_upload_limit'] ) {
546
+ $show_file_upload_limit .= ',' . $type['slug'];
547
+ }
548
+ }
549
  $advanced_question_option = array(
550
  'comments' => array(
551
  'label' => __( 'Comment Field', 'quiz-master-next' ),
575
  '1' => __( 'Yes', 'quiz-master-next' ),
576
  ),
577
  'default' => '0',
578
+ 'show' => '3, 14' . $show_autofill,
579
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Hide-Autofill',
580
  ),
581
  'limit_text' => array(
583
  'type' => 'text',
584
  'priority' => '7',
585
  'default' => '',
586
+ 'show' => '3, 5, 7, 14' . $show_limit_text,
587
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Limit-Text',
588
  ),
589
  'limit_multiple_response' => array(
591
  'type' => 'text',
592
  'priority' => '8',
593
  'default' => '',
594
+ 'show' => '4,10' . $show_limit_multiple_response,
595
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Limit-Multiple-Choice',
596
  ),
597
  'file_upload_type' => array(
607
  'video/mp4' => __( 'Video', 'quiz-master-next' ),
608
  ),
609
  'default' => 'image',
610
+ 'show' => '11' . $show_file_upload_type,
611
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#Allow-File-Type',
612
  ),
613
  'file_upload_limit' => array(
615
  'type' => 'number',
616
  'priority' => '9',
617
  'default' => '',
618
+ 'show' => '11' . $show_file_upload_limit,
619
  'documentation_link' => 'https://quizandsurveymaster.com/docs/v7/advanced-options/#File-Upload-Limit',
620
  ),
621
  );
676
  </div>
677
  </div>
678
 
679
+ <?php add_action( 'admin_footer', 'qsm_options_questions_tab_template' ); ?>
680
 
681
  <div class="qsm-popup qsm-popup-slide" id="modal-7" aria-hidden="false">
682
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close="">
789
  </div>
790
  </div>
791
 
792
+ <?php
793
  }
794
 
795
  add_action( 'wp_ajax_qsm_save_pages', 'qsm_ajax_save_pages' );
806
  }
807
 
808
  global $mlwQuizMasterNext;
809
+ $json = array(
810
  'status' => 'error',
811
  );
812
 
829
  /**
830
  * Loads all the questions and echos out JSON
831
  *
832
+ * @since 0.1.0
833
  * @return void
834
  */
835
  function qsm_load_all_quiz_questions_ajax() {
861
  */
862
  function qsm_send_data_sendy() {
863
  if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'ajax-nonce-sendy-save' ) ) {
864
+ die( 'Busted!' );
865
  }
866
 
867
  $sendy_url = 'http://sendy.expresstech.io';
996
  wp_die();
997
  }
998
  $question_id = isset( $_POST['question_id'] ) ? intval( $_POST['question_id'] ) : 0;
999
+ if ( $question_id ) {
1000
  global $wpdb;
1001
  $wpdb->delete( $wpdb->prefix . 'mlw_questions', array( 'question_id' => $question_id ) );
1002
  echo wp_json_encode(
1016
  add_action( 'wp_ajax_save_new_category', 'qsm_save_new_category' );
1017
 
1018
  function qsm_save_new_category() {
 
1019
  $category = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
1020
  $parent = isset( $_POST['parent'] ) ? intval( $_POST['parent'] ) : '';
1021
+ $parent = ( -1 == $parent ) ? 0 : $parent;
1022
  $term_array = wp_insert_term(
1023
  $category,
1024
  'qsm_category',
1035
  *
1036
  * @since 7.3.5
1037
  */
1038
+ function qsm_options_questions_tab_template() {
1039
  ?>
1040
  <!-- View for Page -->
1041
  <script type="text/template" id="tmpl-page">
1110
  <# } else { #>
1111
  <div><input type="text" class="answer-points" value="{{data.points}}" placeholder="Points"/></div>
1112
  <# } #>
1113
+ <?php do_action( 'qsm_admin_single_answer_option_fields' ); ?>
1114
  </div>
1115
  </script>
1116
  <?php
1117
+ do_action( 'qsm_admin_after_single_answer_template' );
1118
  }
1119
  ?>
php/admin/options-page-results-page-tab.php CHANGED
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  */
17
  function qsm_options_results_tab() {
18
  global $mlwQuizMasterNext;
19
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Results Pages', 'quiz-master-next' ), 'qsm_options_results_tab_content' );
20
  }
21
  add_action( 'plugins_loaded', 'qsm_options_results_tab', 5 );
22
 
@@ -36,14 +36,6 @@ function qsm_options_results_tab_content() {
36
  'rest_user_nonce' => wp_create_nonce( 'wp_rest_nonce_' . $quiz_id . '_' . $user_id ),
37
  );
38
  wp_localize_script( 'qsm_admin_js', 'qsmResultsObject', $js_data );
39
- $categories = array();
40
- $enabled = get_option( 'qsm_multiple_category_enabled' );
41
- if ( $enabled && 'cancelled' !== $enabled ) {
42
- $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 );
43
- } else {
44
- $query = $wpdb->prepare( "SELECT DISTINCT category FROM {$wpdb->prefix}mlw_questions WHERE category <> '' AND quiz_id = %d", $quiz_id );
45
- }
46
- $categories = $wpdb->get_results( $query, ARRAY_N );
47
  ?>
48
 
49
  <!-- Results Page Section -->
@@ -78,18 +70,26 @@ function qsm_options_results_tab_content() {
78
  </header>
79
  <main class="qsm-popup__content" id="show-all-variable-content">
80
  <?php
81
- $variable_list = qsm_text_template_variable_list();
82
- $variable_list['Core']['%POLL_RESULTS_X%'] = __( 'X = Question ID Note: only supported for multiple choice answers', 'quiz-master-next' );
83
- $variable_list['Core']['%RESULT_ID%'] = __( 'Show result id', 'quiz-master-next' );
84
- //filter to add or remove variables from variable list for pdf tab
85
- $variable_list = apply_filters( 'qsm_text_variable_list_result', $variable_list );
86
- if ( $variable_list ) {
87
- foreach ( $variable_list as $category_name => $category_variables ) {
 
 
 
 
 
 
 
 
 
 
 
 
88
  ?>
89
- <div><h2><?php echo esc_attr( $category_name );?></h2></div>
90
- <?php
91
- foreach ( $category_variables as $variable_key => $variable ) {
92
- ?>
93
  <div class="popup-template-span-wrap">
94
  <span class="qsm-text-template-span">
95
  <span class="button button-default template-variable"><?php echo esc_attr( $variable_key ); ?></span>
@@ -101,11 +101,12 @@ function qsm_options_results_tab_content() {
101
  </span>
102
  </span>
103
  </div>
104
- <?php
105
- }
106
  }
107
  }
108
- ?>
 
 
109
  </main>
110
  <footer class="qsm-popup__footer" style="text-align: right;">
111
  <button class="button button-default" data-micromodal-close=""
@@ -122,6 +123,16 @@ function qsm_options_results_tab_content() {
122
  * @since 7.3.5
123
  */
124
  function qsm_options_results_tab_template(){
 
 
 
 
 
 
 
 
 
 
125
  ?>
126
  <script type="text/template" id="tmpl-results-page">
127
  <div class="results-page">
@@ -155,15 +166,18 @@ function qsm_options_results_tab_template(){
155
  <script type="text/template" id="tmpl-results-page-condition">
156
  <div class="results-page-condition">
157
  <button class="delete-condition-button"><span class="dashicons dashicons-trash"></span></button>
158
- <?php if ( ! empty( $categories ) ) { ?>
159
- <select class="results-page-condition-category">
160
- <option value="" <# if (data.category == '') { #>selected<# } #>><?php esc_html_e( 'Quiz', 'quiz-master-next' ); ?></option>
161
- <option value="" disabled><?php esc_html_e( '---Select Category---', 'quiz-master-next' ); ?></option>
162
  <?php foreach ( $categories as $cat ) { ?>
163
  <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>
164
  <?php } ?>
165
- </select>
166
- <?php } ?>
 
 
 
167
  <select class="results-page-condition-criteria">
168
  <option value="points" <# if (data.criteria == 'points') { #>selected<# } #>><?php esc_html_e( 'Total points earned', 'quiz-master-next' ); ?></option>
169
  <option value="score" <# if (data.criteria == 'score') { #>selected<# } #>><?php esc_html_e( 'Correct score percentage', 'quiz-master-next' ); ?></option>
16
  */
17
  function qsm_options_results_tab() {
18
  global $mlwQuizMasterNext;
19
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Results Pages', 'quiz-master-next' ), 'qsm_options_results_tab_content', 'results-pages' );
20
  }
21
  add_action( 'plugins_loaded', 'qsm_options_results_tab', 5 );
22
 
36
  'rest_user_nonce' => wp_create_nonce( 'wp_rest_nonce_' . $quiz_id . '_' . $user_id ),
37
  );
38
  wp_localize_script( 'qsm_admin_js', 'qsmResultsObject', $js_data );
 
 
 
 
 
 
 
 
39
  ?>
40
 
41
  <!-- Results Page Section -->
70
  </header>
71
  <main class="qsm-popup__content" id="show-all-variable-content">
72
  <?php
73
+ $variable_list = qsm_text_template_variable_list();
74
+ $variable_list['Core']['%POLL_RESULTS_X%'] = __( 'X = Question ID Note: only supported for multiple choice answers', 'quiz-master-next' );
75
+ $variable_list['Core']['%RESULT_ID%'] = __( 'Show result id', 'quiz-master-next' );
76
+ //filter to add or remove variables from variable list for pdf tab
77
+ $variable_list = apply_filters( 'qsm_text_variable_list_result', $variable_list );
78
+ if ( $variable_list ) {
79
+ //sort $variable list for backward compatibility
80
+ foreach ( $variable_list as $variable_name => $variable_value ) {
81
+ if ( ! is_array( $variable_value ) ) {
82
+ $variable_list['Other Variables'][ $variable_name ] = $variable_value ;
83
+ }
84
+ }
85
+ foreach ( $variable_list as $category_name => $category_variables ) {
86
+ //check if the $category_variables is an array for backward compatibility
87
+ if ( is_array( $category_variables ) ) {
88
+ ?>
89
+ <div><h2><?php echo esc_attr( $category_name );?></h2></div>
90
+ <?php
91
+ foreach ( $category_variables as $variable_key => $variable ) {
92
  ?>
 
 
 
 
93
  <div class="popup-template-span-wrap">
94
  <span class="qsm-text-template-span">
95
  <span class="button button-default template-variable"><?php echo esc_attr( $variable_key ); ?></span>
101
  </span>
102
  </span>
103
  </div>
104
+ <?php
 
105
  }
106
  }
107
+ }
108
+ }
109
+ ?>
110
  </main>
111
  <footer class="qsm-popup__footer" style="text-align: right;">
112
  <button class="button button-default" data-micromodal-close=""
123
  * @since 7.3.5
124
  */
125
  function qsm_options_results_tab_template(){
126
+ global $wpdb;
127
+ $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : '';
128
+ $categories = array();
129
+ $enabled = get_option( 'qsm_multiple_category_enabled' );
130
+ if ( $enabled && 'cancelled' !== $enabled ) {
131
+ $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 );
132
+ } else {
133
+ $query = $wpdb->prepare( "SELECT DISTINCT category FROM {$wpdb->prefix}mlw_questions WHERE category <> '' AND quiz_id = %d", $quiz_id );
134
+ }
135
+ $categories = $wpdb->get_results( $query, ARRAY_N );
136
  ?>
137
  <script type="text/template" id="tmpl-results-page">
138
  <div class="results-page">
166
  <script type="text/template" id="tmpl-results-page-condition">
167
  <div class="results-page-condition">
168
  <button class="delete-condition-button"><span class="dashicons dashicons-trash"></span></button>
169
+ <select class="results-page-condition-category">
170
+ <option value="" <# if (data.category == '') { #>selected<# } #>><?php esc_html_e( 'Quiz', 'quiz-master-next' ); ?></option>
171
+ <option value="" disabled><?php esc_html_e( '---Select Category---', 'quiz-master-next' ); ?></option>
172
+ <?php if ( ! empty( $categories ) ) { ?>
173
  <?php foreach ( $categories as $cat ) { ?>
174
  <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>
175
  <?php } ?>
176
+ <?php } else { ?>
177
+ <option value="" disabled><?php esc_html_e( 'No Categories Available', 'quiz-master-next' ); ?></option>
178
+ <?php } ?>
179
+ </select>
180
+
181
  <select class="results-page-condition-criteria">
182
  <option value="points" <# if (data.criteria == 'points') { #>selected<# } #>><?php esc_html_e( 'Total points earned', 'quiz-master-next' ); ?></option>
183
  <option value="score" <# if (data.criteria == 'score') { #>selected<# } #>><?php esc_html_e( 'Correct score percentage', 'quiz-master-next' ); ?></option>
php/admin/options-page-style-tab.php CHANGED
@@ -21,7 +21,7 @@ if ( ! defined( 'ABSPATH' ) ) {
21
  */
22
  function qsm_settings_style_tab() {
23
  global $mlwQuizMasterNext;
24
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Style', 'quiz-master-next' ), 'qsm_options_styling_tab_content' );
25
  }
26
  add_action( 'plugins_loaded', 'qsm_settings_style_tab', 5 );
27
 
@@ -45,7 +45,7 @@ function qsm_options_styling_tab_content() {
45
  $results = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}mlw_quizzes SET quiz_stye=%s, theme_selected=%s, last_activity=%s WHERE quiz_id=%d", $quiz_style, $quiz_theme, gmdate( 'Y-m-d H:i:s' ), $style_quiz_id ) );
46
  if ( false !== $results ) {
47
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The style has been saved successfully.', 'quiz-master-next' ), 'success' );
48
- $mlwQuizMasterNext->audit_manager->new_audit( "Styles Have Been Saved For Quiz Number $style_quiz_id" );
49
  } else {
50
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Error occured when trying to save the styles. Please try again.', 'quiz-master-next' ), 'error' );
51
  $mlwQuizMasterNext->log_manager->add( 'Error saving styles', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' );
@@ -88,7 +88,7 @@ function qsm_options_styling_tab_content() {
88
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Featured image updated successfully.', 'quiz-master-next' ), 'success' );
89
  } else {
90
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The theme is applied successfully.', 'quiz-master-next' ), 'success' );
91
- $mlwQuizMasterNext->audit_manager->new_audit( "Styles Have Been Saved For Quiz Number $quiz_id" );
92
  }
93
  $featured_image = isset( $_POST['quiz_featured_image'] ) ? esc_url_raw( wp_unslash( $_POST['quiz_featured_image'] ) ) : '';
94
  if ( ! empty( $quiz_id ) ) {
@@ -114,7 +114,7 @@ function qsm_options_styling_tab_content() {
114
  __( 'The theme settings saved successfully.', 'quiz-master-next' ),
115
  'success'
116
  );
117
- $mlwQuizMasterNext->audit_manager->new_audit( "Theme settings Have Been Saved For Quiz Number $quiz_id" );
118
  }
119
  $folder_name = QSM_THEME_PATH;
120
  $folder_slug = QSM_THEME_SLUG;
@@ -313,7 +313,7 @@ function qsm_display_theme_settings() {
313
  global $mlwQuizMasterNext, $wpdb;
314
  $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0;
315
  $theme_id = $mlwQuizMasterNext->theme_settings->get_active_quiz_theme( $quiz_id );
316
-
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'] );
21
  */
22
  function qsm_settings_style_tab() {
23
  global $mlwQuizMasterNext;
24
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Style', 'quiz-master-next' ), 'qsm_options_styling_tab_content', 'style' );
25
  }
26
  add_action( 'plugins_loaded', 'qsm_settings_style_tab', 5 );
27
 
45
  $results = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}mlw_quizzes SET quiz_stye=%s, theme_selected=%s, last_activity=%s WHERE quiz_id=%d", $quiz_style, $quiz_theme, gmdate( 'Y-m-d H:i:s' ), $style_quiz_id ) );
46
  if ( false !== $results ) {
47
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The style has been saved successfully.', 'quiz-master-next' ), 'success' );
48
+ $mlwQuizMasterNext->audit_manager->new_audit( "Styles Have Been Saved", $style_quiz_id, "" );
49
  } else {
50
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Error occured when trying to save the styles. Please try again.', 'quiz-master-next' ), 'error' );
51
  $mlwQuizMasterNext->log_manager->add( 'Error saving styles', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' );
88
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Featured image updated successfully.', 'quiz-master-next' ), 'success' );
89
  } else {
90
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The theme is applied successfully.', 'quiz-master-next' ), 'success' );
91
+ $mlwQuizMasterNext->audit_manager->new_audit( "Styles Have Been Saved", $quiz_id, "" );
92
  }
93
  $featured_image = isset( $_POST['quiz_featured_image'] ) ? esc_url_raw( wp_unslash( $_POST['quiz_featured_image'] ) ) : '';
94
  if ( ! empty( $quiz_id ) ) {
114
  __( 'The theme settings saved successfully.', 'quiz-master-next' ),
115
  'success'
116
  );
117
+ $mlwQuizMasterNext->audit_manager->new_audit( "Theme settings Have Been Saved", $quiz_id, "" );
118
  }
119
  $folder_name = QSM_THEME_PATH;
120
  $folder_slug = QSM_THEME_SLUG;
313
  global $mlwQuizMasterNext, $wpdb;
314
  $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0;
315
  $theme_id = $mlwQuizMasterNext->theme_settings->get_active_quiz_theme( $quiz_id );
316
+
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'] );
php/admin/options-page-text-tab.php CHANGED
@@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
9
  */
10
  function qmn_settings_text_tab() {
11
  global $mlwQuizMasterNext;
12
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Text', 'quiz-master-next' ), 'mlw_options_text_tab_content' );
13
  }
14
  add_action( "plugins_loaded", 'qmn_settings_text_tab', 5 );
15
 
9
  */
10
  function qmn_settings_text_tab() {
11
  global $mlwQuizMasterNext;
12
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Text', 'quiz-master-next' ), 'mlw_options_text_tab_content', 'text' );
13
  }
14
  add_action( "plugins_loaded", 'qmn_settings_text_tab', 5 );
15
 
php/admin/quiz-options-page.php CHANGED
@@ -64,7 +64,7 @@ function qsm_generate_quiz_options() {
64
  $update_status = wp_update_post( $arg_post_arr );
65
  if ( false !== $update_status ) {
66
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Quiz status has been updated successfully to publish.', 'quiz-master-next' ), 'success' );
67
- $mlwQuizMasterNext->audit_manager->new_audit( "Quiz/Survey Status Has Been Updated: $quiz_post_id" );
68
  } else {
69
  $mlwQuizMasterNext->alertManager->newAlert( __( 'An error occurred while trying to update the status of your quiz or survey. Please try again.', 'quiz-master-next' ), 'error' );
70
  $mlwQuizMasterNext->log_manager->add( 'Error when updating quiz status', "", 0, 'error' );
@@ -120,6 +120,11 @@ function qsm_generate_quiz_options() {
120
  </a>
121
  </h1>
122
  <div class="qsm-alerts-placeholder"></div>
 
 
 
 
 
123
  <?php if ( $quiz_id ) { ?>
124
  <nav class="nav-tab-wrapper">
125
  <?php
@@ -154,12 +159,9 @@ function qsm_generate_quiz_options() {
154
  </div>
155
  <?php
156
  }
157
- // Shows alerts, ads, then tab content.
 
158
  ?>
159
- <div class="qsm-alerts">
160
- <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
161
- </div>
162
- <?php qsm_show_adverts(); ?>
163
  </div>
164
  <div class="qsm-popup qsm-popup-slide" id="modal-3" aria-hidden="false">
165
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close="">
@@ -177,8 +179,8 @@ function qsm_generate_quiz_options() {
177
  </form>
178
  </main>
179
  <footer class="qsm-popup__footer">
180
- <button id="edit-name-button" class="qsm-popup__btn qsm-popup__btn-primary">Edit</button>
181
- <button class="qsm-popup__btn" data-micromodal-close="" aria-label="Close this dialog window">Cancel</button>
182
  </footer>
183
  </div>
184
  </div>
64
  $update_status = wp_update_post( $arg_post_arr );
65
  if ( false !== $update_status ) {
66
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Quiz status has been updated successfully to publish.', 'quiz-master-next' ), 'success' );
67
+ $mlwQuizMasterNext->audit_manager->new_audit( "Quiz/Survey Status Has Been Updated", $quiz_id,"" );
68
  } else {
69
  $mlwQuizMasterNext->alertManager->newAlert( __( 'An error occurred while trying to update the status of your quiz or survey. Please try again.', 'quiz-master-next' ), 'error' );
70
  $mlwQuizMasterNext->log_manager->add( 'Error when updating quiz status', "", 0, 'error' );
120
  </a>
121
  </h1>
122
  <div class="qsm-alerts-placeholder"></div>
123
+ <!-- Shows warnings, alerts then tab content -->
124
+ <?php $mlwQuizMasterNext->alertManager->showWarnings(); ?>
125
+ <div class="qsm-alerts">
126
+ <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
127
+ </div>
128
  <?php if ( $quiz_id ) { ?>
129
  <nav class="nav-tab-wrapper">
130
  <?php
159
  </div>
160
  <?php
161
  }
162
+ // Shows ads
163
+ qsm_show_adverts();
164
  ?>
 
 
 
 
165
  </div>
166
  <div class="qsm-popup qsm-popup-slide" id="modal-3" aria-hidden="false">
167
  <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close="">
179
  </form>
180
  </main>
181
  <footer class="qsm-popup__footer">
182
+ <button id="edit-name-button" class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Save', 'quiz-master-next' ); ?></button>
183
+ <button class="qsm-popup__btn" data-micromodal-close="" aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
184
  </footer>
185
  </div>
186
  </div>
php/admin/quizzes-page.php CHANGED
@@ -24,12 +24,11 @@ function qsm_generate_quizzes_surveys_page() {
24
  global $wpdb;
25
  global $mlwQuizMasterNext;
26
 
27
-
28
  // Delete quiz.
29
  if ( isset( $_POST['qsm_delete_quiz_nonce'], $_POST['delete_quiz_id'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['qsm_delete_quiz_nonce'] ) ), 'qsm_delete_quiz' ) ) {
30
- $quiz_id = sanitize_text_field( wp_unslash( $_POST['delete_quiz_id'] ) );
31
- $quiz_id = intval( str_replace( 'QID', '', $quiz_id ) );
32
- do_action( 'qsm_before_delete_quiz' , $quiz_id );
33
  $quiz_name = isset( $_POST['delete_quiz_name'] ) ? sanitize_text_field( wp_unslash( $_POST['delete_quiz_name'] ) ) : '';
34
  $mlwQuizMasterNext->quizCreator->delete_quiz( $quiz_id, $quiz_name );
35
  }
@@ -45,27 +44,32 @@ function qsm_generate_quizzes_surveys_page() {
45
  // Resets stats for a quiz.
46
  if ( isset( $_POST['qsm_reset_stats_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['qsm_reset_stats_nonce'] ) ), 'qsm_reset_stats' ) ) {
47
  $quiz_id = isset( $_POST['reset_quiz_id'] ) ? intval( $_POST['reset_quiz_id'] ) : '';
48
- $results = $wpdb->update(
49
- $wpdb->prefix . 'mlw_quizzes',
50
- array(
51
- 'quiz_views' => 0,
52
- 'quiz_taken' => 0,
53
- 'last_activity' => gmdate( 'Y-m-d H:i:s' ),
54
- ),
55
- array( 'quiz_id' => $quiz_id ),
56
- array(
57
- '%d',
58
- '%d',
59
- '%s',
60
- ),
61
- array( '%d' )
62
- );
63
- if ( false !== $results ) {
64
- $mlwQuizMasterNext->alertManager->newAlert( __( 'The stats has been reset successfully.', 'quiz-master-next' ), 'success' );
65
- $mlwQuizMasterNext->audit_manager->new_audit( "Quiz Stats Have Been Reset For Quiz Number $quiz_id" );
66
  } else {
67
- $mlwQuizMasterNext->alertManager->newAlert( __( 'Error trying to reset stats. Please try again.', 'quiz-master-next' ), 'error' );
68
- $mlwQuizMasterNext->log_manager->add( 'Error resetting stats', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
  }
71
 
@@ -110,8 +114,8 @@ function qsm_generate_quizzes_surveys_page() {
110
  $num_of_pages = ceil( $total / $limit );
111
  } else {
112
  $condition = ' WHERE deleted=0';
113
- $condition = apply_filters( 'quiz_query_condition_clause', $condition );
114
- $total = $wpdb->get_var( stripslashes($wpdb->prepare( "SELECT COUNT(`quiz_id`) FROM {$wpdb->prefix}mlw_quizzes %1s", $condition ) ));
115
  $num_of_pages = ceil( $total / $limit );
116
  }
117
 
@@ -151,7 +155,7 @@ function qsm_generate_quizzes_surveys_page() {
151
  if ( isset( $_POST['btnSearchQuiz'] ) && isset( $_POST['s'] ) && ! empty( $_POST['s'] ) ) {
152
  $search_quiz = htmlspecialchars( sanitize_text_field( wp_unslash( $_POST['s'] ) ), ENT_QUOTES );
153
  $condition = " WHERE deleted=0 AND quiz_name LIKE '%$search_quiz%'";
154
- $condition = apply_filters( 'quiz_query_condition_clause', $condition );
155
  $qry = stripslashes( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_quizzes%1s", $condition ) );
156
  $quizzes = $wpdb->get_results( $qry );
157
 
@@ -218,463 +222,467 @@ function qsm_generate_quizzes_surveys_page() {
218
  $total_count = count( $quiz_json_array );
219
  wp_localize_script( 'qsm_admin_js', 'qsmQuizObject', $quiz_json_array );
220
  ?>
221
- <div class="wrap qsm-quizes-page">
222
- <h1>
223
- <?php esc_html_e( 'Quizzes/Surveys', 'quiz-master-next' ); ?>
224
- <a id="new_quiz_button" href="#" class="add-new-h2"><?php esc_html_e( 'Add New', 'quiz-master-next' ); ?></a>
225
- </h1>
226
- <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
227
- <?php
228
- if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
229
- ?>
230
- <div class="qsm-info-box">
231
- <p><?php esc_html_e( 'Your site is using PHP version', 'quiz-master-next' ); ?>
232
- <?php echo esc_html( PHP_VERSION ); ?>!
233
- <?php esc_html_e( 'Starting in QSM 6.0, your version of PHP will no longer be supported.', 'quiz-master-next' ); ?>
234
- <a href="https://quizandsurveymaster.com/increased-minimum-php-version-qsm-6-0/?utm_campaign=qsm_plugin&utm_medium=plugin&utm_source=minimum-php-notice" target="_blank"
235
- rel="noopener"><?php esc_html_e( "Click here to learn more about QSM's minimum PHP version change.", 'quiz-master-next' ); ?></a>
236
- </p>
237
- </div>
238
- <?php
239
- }
240
- ?>
241
- <form method="POST" id="posts-filter">
242
- <?php wp_nonce_field( 'qsm_search_multiple_delete', 'qsm_search_multiple_delete_nonce' ); ?>
243
- <div class="qsm-quizzes-page-content">
244
- <div class="
245
- <?php
246
- if ( 'false' !== get_option( 'mlw_advert_shows' ) ) {
247
- echo 'qsm-quiz-page-wrapper-with-ads';
248
- } else {
249
- echo 'qsm-quiz-page-wrapper';
250
- }
251
  ?>
252
- ">
253
- <p class="search-box">
254
- <label class="screen-reader-text"
255
- for="quiz_search"><?php esc_html_e( 'Search', 'quiz-master-next' ); ?></label>
256
- <!-- Changed Request to Post -->
257
- <input type="search" id="quiz_search" name="s"
258
- value="<?php echo isset( $_POST['s'] ) && '' !== $_POST['s'] ? esc_attr( sanitize_text_field( wp_unslash( $_POST['s'] ) ) ) : ''; ?>">
259
- <input id="search-submit" class="button" type="submit" name="btnSearchQuiz" value="Search Quiz">
260
- <?php if ( class_exists( 'QSM_Export_Import' ) ) { ?>
261
- <a class="button button-primary"
262
- href="<?php echo esc_url( admin_url() . 'admin.php?page=qmn_addons&tab=export-and-import' ); ?>"
263
- target="_blank" rel="noopener"><?php esc_html_e( 'Import & Export', 'quiz-master-next' ); ?></a>
264
- <?php } else { ?>
265
- <a id="show_import_export_popup" href="#" style="position: relative;top: 0px;"
266
- class="add-new-h2 button-primary"><?php esc_html_e( 'Import & Export', 'quiz-master-next' ); ?></a>
267
- <?php } ?>
268
  </p>
269
- <div class="tablenav top">
270
- <div class="alignleft actions bulkactions">
271
- <select id="bulk-action-top" name="qsm-ql-action-top">
272
- <option selected="selected" value="none"><?php esc_html_e( 'Bulk Actions', 'quiz-master-next' ); ?>
273
- </option>
274
- <option value="delete_pr"><?php esc_html_e( 'Delete Permanently', 'quiz-master-next' ); ?></option>
275
- </select>
276
- <input id="bulk-submit" name="bulk-submit-top" class="button" type="button"
277
- value="<?php esc_attr_e( 'Apply', 'quiz-master-next' ); ?>">
278
- </div>
279
- <div class="tablenav-pages">
280
- <span
281
- class="displaying-num"><?php echo esc_html( number_format_i18n( $total ) . ' ' . sprintf( _n( 'item', 'items', $total, 'quiz-master-next' ), number_format_i18n( $total ) ) ); ?></span>
282
- <span class="pagination-links" <?php
283
- if ( (int) $num_of_pages <= 1 ) {
284
- echo 'style="display:none;"';
285
- }
286
- ?>>
287
- <?php if ( '1' == $paged ) { ?>
288
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>
289
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>
290
- <?php } else { ?>
291
- <a class="first-page button"
292
- href="<?php echo '?page=mlw_quiz_list&paged=1&s=' . esc_attr( $search ); ?>"
293
- title="<?php esc_attr_e( 'Go to the first page', 'quiz-master-next' ); ?>">&laquo;</a>
294
- <a class="prev-page button"
295
- href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $prev_page ) . '&s=' . esc_attr( $search ); ?>"
296
- title="<?php esc_attr_e( 'Go to the previous page', 'quiz-master-next' ); ?>">&lsaquo;</a>
297
- <?php } ?>
298
- <span class="paging-input">
299
- <span class="total-pages"><?php echo esc_html( $paged ); ?></span>
300
- <?php esc_html_e( 'of', 'quiz-master-next' ); ?>
301
- <span class="total-pages"><?php echo esc_html( $num_of_pages ); ?></span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  </span>
303
- <?php if ( $paged === $num_of_pages ) { ?>
304
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>
305
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>
306
- <?php } else { ?>
307
- <a class="next-page button"
308
- href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $next_page ) . '&s=' . esc_attr( $search ); ?>"
309
- title="<?php esc_attr_e( 'Go to the next page', 'quiz-master-next' ); ?>">&rsaquo;</a>
310
- <a class="last-page button"
311
- href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $num_of_pages ) . '&s=' . esc_attr( $search ); ?>"
312
- title="<?php esc_attr_e( 'Go to the last page', 'quiz-master-next' ); ?>">&raquo;</a>
313
- <?php } ?>
314
- </span>
315
  </div>
316
- </div>
317
- <table class="widefat">
318
- <?php
319
- $orderby_slug = '&orderby=title&order=asc';
320
- $orderby_date_slug = '&orderby=date&order=asc';
321
- $orderby_class = $orderby_date_class = 'sortable desc';
322
- // Title order
323
- if ( isset( $_GET['orderby'] ) && sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) === 'title' ) {
324
- if ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'asc' ) {
325
- $orderby_slug = '&orderby=title&order=desc';
326
- $orderby_class = 'sorted asc';
327
- } elseif ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'desc' ) {
328
- $orderby_slug = '&orderby=title&order=asc';
329
- $orderby_class = 'sorted desc';
330
- }
331
- } elseif ( isset( $_GET['orderby'] ) && sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) === 'date' ) {
332
- if ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'asc' ) {
333
- $orderby_date_slug = '&orderby=date&order=desc';
334
- $orderby_date_class = 'sorted asc';
335
- } elseif ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'desc' ) {
336
- $orderby_date_slug = '&orderby=date&order=asc';
337
- $orderby_date_class = 'sorted desc';
338
- }
339
- }
340
- ?>
341
- <thead>
342
- <tr>
343
- <td class="manage-column column-cb check-column" id="cb"><input type="checkbox"
344
- name="delete-all-shortcodes-1" id="delete-all-shortcodes-1" value="0"></td>
345
- <th class="<?php echo esc_attr( $orderby_class ); ?>">
346
- <?php
347
- $paged_slug = isset( $_GET['paged'] ) && '' !== $_GET['paged'] ? '&paged=' . sanitize_text_field( wp_unslash( $_GET['paged'] ) ) : '';
348
- $searched_slug = isset( $_GET['s'] ) && '' !== $_GET['s'] ? '&s=' . sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '';
349
- $sorting_url = '?page=mlw_quiz_list' . $paged_slug . $searched_slug;
350
- ?>
351
- <a href="<?php echo esc_url( $sorting_url . $orderby_slug ); ?>">
352
- <span><?php esc_html_e( 'Title', 'quiz-master-next' ); ?></span>
353
- <span class="sorting-indicator"></span>
354
- </a>
355
- </th>
356
- <th><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></th>
357
- <th><?php esc_html_e( 'Views', 'quiz-master-next' ); ?></th>
358
- <th><?php esc_html_e( 'Participants', 'quiz-master-next' ); ?></th>
359
- <th class="<?php echo esc_attr( $orderby_date_class ); ?>">
360
- <a href="<?php echo esc_url( $sorting_url . $orderby_date_slug ); ?>">
361
- <span><?php esc_html_e( 'Last Modified', 'quiz-master-next' ); ?></span>
362
- <span class="sorting-indicator"></span>
363
- </a>
364
- </th>
365
- </tr>
366
- </thead>
367
- <tbody id="the-list">
368
- <?php
369
- if ( $quiz_json_array ) {
370
- foreach ( $quiz_json_array as $key => $single_arr ) {
371
- ?>
372
- <tr class="qsm-quiz-row" data-id="<?php echo esc_attr( $single_arr['id'] ); ?>">
373
- <th class="check-column">
374
- <input type="checkbox" class="chk_remove_all" name="chk_remove_all[]"
375
- id="chk_remove_all" value="<?php echo esc_attr( $single_arr['id'] ); ?>">
376
- </th>
377
- <td class="post-title column-title">
378
- <a class="row-title" href="admin.php?page=mlw_quiz_options&&quiz_id=<?php echo esc_attr( $single_arr['id'] ); ?>" aria-label="<?php echo esc_attr( $single_arr['name'] ); ?>"><?php echo esc_html( $single_arr['name'] ); ?> <strong style="color: #222; text-transform: capitalize;"><?php echo esc_html( 'publish' !== $single_arr['post_status'] ? '— ' . $single_arr['post_status'] : '' ); ?></strong>
379
- </a>
380
- <div class="row-actions">
381
- <a class="qsm-action-link" href="admin.php?page=mlw_quiz_options&&quiz_id=<?php echo esc_attr( $single_arr['id'] ); ?>"><?php esc_html_e( 'Edit', 'quiz-master-next' ); ?></a> |
382
- <a class="qsm-action-link qsm-action-link-duplicate" href="#"><?php esc_html_e( 'Duplicate', 'quiz-master-next' ); ?></a> |
383
- <a class="qsm-action-link qsm-action-link-delete" href="#"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></a> |
384
- <a class="qsm-action-link" href="admin.php?page=mlw_quiz_results&quiz_id=<?php echo esc_attr( $single_arr['id'] ); ?>"><?php esc_html_e( 'View Results', 'quiz-master-next' ); ?></a> |
385
- <a class="qsm-action-link" target="_blank" rel="noopener" href="<?php echo esc_url( $single_arr['link'] ); ?>"><?php esc_html_e( 'Preview', 'quiz-master-next' ); ?></a>
386
- </div>
387
- </td>
388
- <td>
389
- <a href="#" class="qsm-list-shortcode-view">
390
- <span class="dashicons dashicons-welcome-view-site"></span>
391
- </a>
392
- <div class="sc-content sc-embed">[qsm quiz=<?php echo esc_attr( $single_arr['id'] ); ?>]</div>
393
- <div class="sc-content sc-link">[qsm_link id=<?php echo esc_attr( $single_arr['id'] ); ?>]<?php esc_html_e( 'Click here', 'quiz-master-next' ); ?>[/qsm_link]
394
- </div>
395
- </td>
396
- <td>
397
- <?php echo esc_html( $single_arr['views'] ); ?>
398
- <div class="row-actions">
399
- <a class="qsm-action-link qsm-action-link-reset"
400
- href="#"><?php esc_html_e( 'Reset', 'quiz-master-next' ); ?></a>
401
- </div>
402
- </td>
403
- <td class="comments column-comments" style="text-align: left;">
404
- <span class="post-com-count post-com-count-approved">
405
- <span class="comment-count-approved" aria-hidden="true"><?php echo esc_html( $single_arr['taken'] ); ?></span>
406
- <span class="screen-reader-text"><?php echo esc_html( $single_arr['taken'] . __( 'Participants', 'quiz-master-next' ) ) ; ?></span>
407
- </span>
408
- </td>
409
- <td>
410
- <abbr title="<?php echo esc_html( $single_arr['lastActivityDateTime'] ); ?>"><?php echo esc_html( $single_arr['lastActivity'] ); ?></abbr>
411
- </td>
412
- </tr>
413
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  }
415
- } else {
416
- ?>
417
- <tr>
418
- <td colspan="6" style="text-align: center;">
419
- <?php esc_html_e( 'No Quiz found!', 'quiz-master-next' ); ?>
420
- </td>
421
- </tr>
422
- <?php
423
  }
424
  ?>
425
- </tbody>
426
- <tfoot>
427
- <tr>
428
- <td class="manage-column column-cb check-column" id="cb"><input type="checkbox"
429
- name="delete-all-shortcodes-2" id="delete-all-shortcodes-2" value="0"></td>
430
- <th class="<?php echo esc_attr( $orderby_class ); ?>" scope="col">
431
- <a href="<?php echo esc_url( $sorting_url . $orderby_slug ); ?>">
432
- <span><?php esc_html_e( 'Title', 'quiz-master-next' ); ?></span>
433
- <span class="sorting-indicator"></span>
434
- </a>
435
- </th>
436
- <th><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></th>
437
- <th><?php esc_html_e( 'Views', 'quiz-master-next' ); ?></th>
438
- <th><?php esc_html_e( 'Participants', 'quiz-master-next' ); ?></th>
439
- <th class="<?php echo esc_attr( $orderby_date_class ); ?>" scope="col">
440
- <a href="<?php echo esc_url( $sorting_url . $orderby_date_slug ); ?>">
441
- <span><?php esc_html_e( 'Last Modified', 'quiz-master-next' ); ?></span>
442
- <span class="sorting-indicator"></span>
443
- </a>
444
- </th>
445
- </tr>
446
- </tfoot>
447
- </table>
448
- <div class="tablenav bottom">
449
- <select id="bulk-action-bottom" name="qsm-ql-action-bottom">
450
- <option selected="selected" value="none"><?php esc_html_e( 'Bulk Actions', 'quiz-master-next' ); ?>
451
- </option>
452
- <option value="delete_pr"><?php esc_html_e( 'Delete Permanently', 'quiz-master-next' ); ?></option>
453
- </select>
454
- <input id="bulk-submit" name="bulk-submit-bottom" class="button" type="button"
455
- value="<?php esc_attr_e( 'Apply', 'quiz-master-next' ); ?>">
456
- <div class="tablenav-pages">
457
- <span
458
- class="displaying-num"><?php echo esc_html( number_format_i18n( $total ) . ' ' . sprintf( _n( 'item', 'items', $total, 'quiz-master-next' ), number_format_i18n( $total ) ) ); ?></span>
459
- <span class="pagination-links" <?php
460
- if ( (int) $num_of_pages <= 1 ) {
461
- echo 'style="display:none;"';
462
- }
463
- ?>>
464
- <?php if ( '1' == $paged ) { ?>
465
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>
466
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>
467
- <?php } else { ?>
468
- <a class="first-page button"
469
- href="<?php echo '?page=mlw_quiz_list&paged=1&s=' . esc_attr( $search ); ?>"
470
- title="<?php esc_attr_e( 'Go to the first page', 'quiz-master-next' ); ?>">&laquo;</a>
471
- <a class="prev-page button"
472
- href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $prev_page ) . '&s=' . esc_attr( $search ); ?>"
473
- title="<?php esc_attr_e( 'Go to the previous page', 'quiz-master-next' ); ?>">&lsaquo;</a>
474
- <?php } ?>
475
- <span class="paging-input">
476
- <span class="total-pages"><?php echo esc_html( $paged ); ?></span>
477
- <?php esc_html_e( 'of', 'quiz-master-next' ); ?>
478
- <span class="total-pages"><?php echo esc_html( $num_of_pages ); ?></span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  </span>
480
- <?php if ( $paged === $num_of_pages ) { ?>
481
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>
482
- <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>
483
- <?php } else { ?>
484
- <a class="next-page button"
485
- href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $next_page ) . '&s=' . esc_attr( $search ); ?>"
486
- title="<?php esc_attr_e( 'Go to the next page', 'quiz-master-next' ); ?>">&rsaquo;</a>
487
- <a class="last-page button"
488
- href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $num_of_pages ) . '&s=' . esc_attr( $search ); ?>"
489
- title="<?php esc_attr_e( 'Go to the last page', 'quiz-master-next' ); ?>">&raquo;</a>
490
- <?php } ?>
491
- </span>
492
  </div>
493
  </div>
494
  </div>
495
- </div>
496
- </form>
497
-
498
- <!-- Popup for resetting stats -->
499
- <div class="qsm-popup qsm-popup-slide" id="modal-1" aria-hidden="true">
500
- <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
501
- <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
502
- <header class="qsm-popup__header">
503
- <h2 class="qsm-popup__title" id="modal-1-title">
504
- <?php esc_html_e( 'Reset stats for this quiz?', 'quiz-master-next' ); ?></h2>
505
- <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
506
- </header>
507
- <main class="qsm-popup__content" id="modal-1-content">
508
- <p><?php esc_html_e( 'Are you sure you want to reset the stats to 0? All views and taken stats for this quiz will be reset. This is permanent and cannot be undone.', 'quiz-master-next' ); ?>
509
- </p>
510
- <form action="" method="post" id="reset_quiz_form">
511
- <?php wp_nonce_field( 'qsm_reset_stats', 'qsm_reset_stats_nonce' ); ?>
512
- <input type="hidden" id="reset_quiz_id" name="reset_quiz_id" value="0" />
513
- </form>
514
- </main>
515
- <footer class="qsm-popup__footer">
516
- <button id="reset-stats-button"
517
- class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Reset All Stats For Quiz', 'quiz-master-next' ); ?></button>
518
- <button class="qsm-popup__btn" data-micromodal-close
519
- aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
520
- </footer>
521
  </div>
522
  </div>
523
- </div>
524
 
525
- <!-- Popup for new quiz -->
526
- <?php qsm_create_new_quiz_wizard(); ?>
527
-
528
- <!-- Popup for duplicate quiz -->
529
- <div class="qsm-popup qsm-popup-slide" id="modal-4" aria-hidden="true">
530
- <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
531
- <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-4-title">
532
- <header class="qsm-popup__header">
533
- <h2 class="qsm-popup__title" id="modal-4-title"><?php esc_html_e( 'Duplicate', 'quiz-master-next' ); ?></h2>
534
- <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
535
- </header>
536
- <main class="qsm-popup__content" id="modal-4-content">
537
- <form action='' method='post' id="duplicate-quiz-form">
538
- <label
539
- for="duplicate_questions"><?php esc_html_e( 'Duplicate questions also?', 'quiz-master-next' ); ?></label><input
540
- type="checkbox" name="duplicate_questions" id="duplicate_questions" /><br />
541
- <br />
542
- <label
543
- for="duplicate_new_quiz_name"><?php esc_html_e( 'Name Of New Quiz Or Survey:', 'quiz-master-next' ); ?></label><input
544
- type="text" id="duplicate_new_quiz_name" name="duplicate_new_quiz_name" />
545
- <input type="hidden" id="duplicate_quiz_id" name="duplicate_quiz_id" />
546
- <?php wp_nonce_field( 'qsm_duplicate_quiz', 'qsm_duplicate_quiz_nonce' ); ?>
547
- </form>
548
- </main>
549
- <footer class="qsm-popup__footer">
550
- <button id="duplicate-quiz-button"
551
- class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Duplicate', 'quiz-master-next' ); ?></button>
552
- <button class="qsm-popup__btn" data-micromodal-close
553
- aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
554
- </footer>
 
555
  </div>
556
  </div>
557
- </div>
558
 
559
- <!-- Popup for delete quiz -->
560
- <div class="qsm-popup qsm-popup-slide" id="modal-5" aria-hidden="true">
561
- <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
562
- <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
563
- <header class="qsm-popup__header">
564
- <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></h2>
565
- <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
566
- </header>
567
- <main class="qsm-popup__content" id="modal-5-content">
568
- <form action='' method='post' id="delete-quiz-form" style="display:flex; flex-direction:column;">
569
- <h3><b><?php esc_html_e( 'Are you sure you want to delete this quiz or survey?', 'quiz-master-next' ); ?></b>
570
- </h3>
571
- <label>
572
- <input type="checkbox" value="1" name="qsm_delete_question_from_qb" />
573
- <?php esc_html_e( 'Delete question from question bank?', 'quiz-master-next' ); ?>
574
- </label>
575
- <label>
576
- <input type="checkbox" name="qsm_delete_from_db" value="1"/>
577
- <?php esc_html_e( 'Delete items from database?', 'quiz-master-next' ); ?>
578
- </label>
579
- <?php wp_nonce_field( 'qsm_delete_quiz', 'qsm_delete_quiz_nonce' ); ?>
580
- <input type='hidden' id='delete_quiz_id' name='delete_quiz_id' value='' />
581
- <input type='hidden' id='delete_quiz_name' name='delete_quiz_name' value='' />
582
- </form>
583
- </main>
584
- <footer class="qsm-popup__footer">
585
- <button id="delete-quiz-button"
586
- class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></button>
587
- <button class="qsm-popup__btn" data-micromodal-close
588
- aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
589
- </footer>
 
590
  </div>
591
  </div>
592
- </div>
593
- <!-- Popup for bulk delete quiz -->
594
- <div class="qsm-popup qsm-popup-slide" id="modal-bulk-delete" aria-hidden="true">
595
- <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
596
- <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
597
- <header class="qsm-popup__header">
598
- <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Bulk Delete', 'quiz-master-next' ); ?></h2>
599
- <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
600
- </header>
601
- <main class="qsm-popup__content" id="modal-5-content">
602
- <form action='' method='post' id="bult-delete-quiz-form" style="display:flex; flex-direction:column;">
603
- <h3><b><?php esc_html_e( 'Are you sure you want to delete selected quiz or survey?', 'quiz-master-next' ); ?></b>
604
- </h3>
605
- <label>
606
- <input type="checkbox" name="qsm_delete_question_from_qb" checked="checked" />
607
- <?php esc_html_e( 'Delete question from question bank?', 'quiz-master-next' ); ?>
608
- </label>
609
- <label>
610
- <input type="checkbox" name="qsm_delete_from_db" />
611
- <?php esc_html_e( 'Delete items from database?', 'quiz-master-next' ); ?>
612
- </label>
613
- </form>
614
- </main>
615
- <footer class="qsm-popup__footer">
616
- <button id="bulk-delete-quiz-button"
617
- class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></button>
618
- <button class="qsm-popup__btn" data-micromodal-close
619
- aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
620
- </footer>
621
  </div>
622
  </div>
623
- </div>
624
 
625
 
626
- <!-- Popup for export import upsell -->
627
- <div class="qsm-popup qsm-popup-slide" id="modal-export-import" aria-hidden="true">
628
- <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
629
- <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
630
- <header class="qsm-popup__header">
631
- <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Extend QSM', 'quiz-master-next' ); ?>
632
- </h2>
633
- <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
634
- </header>
635
- <main class="qsm-popup__content" id="modal-5-content">
636
- <h3><b><?php esc_html_e( 'Export functionality is provided as Premium addon.', 'quiz-master-next' ); ?></b>
637
- </h3>
638
- </main>
639
- <footer class="qsm-popup__footer">
640
- <a style="color: white; text-decoration: none;"
641
- href="https://quizandsurveymaster.com/downloads/export-import/" target="_blank"
642
- class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Buy Now', 'quiz-master-next' ); ?></a>
643
- <button class="qsm-popup__btn" data-micromodal-close
644
- aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
645
- </footer>
 
646
  </div>
647
  </div>
648
- </div>
649
 
650
- <!-- Popup for delete quiz -->
651
- <div class="qsm-popup qsm-popup-slide" id="modal-6" aria-hidden="true">
652
- <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
653
- <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
654
- <header class="qsm-popup__header">
655
- <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></h2>
656
- <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
657
- </header>
658
- <main class="qsm-popup__content" id="modal-5-content">
659
- <div class="qsm-row" style="margin-bottom: 30px;">
660
- <lable><?php esc_html_e( 'Embed Shortcode', 'quiz-master-next' ); ?></lable>
661
- <input type="text" value="" id="sc-shortcode-model-text" style="width: 72%;padding: 5px;">
662
- <button class="button button-primary" id="sc-copy-shortcode"><span
663
- class="dashicons dashicons-admin-page"></span></button>
664
- </div>
665
- <div class="qsm-row">
666
- <lable><?php esc_html_e( 'Link Shortcode', 'quiz-master-next' ); ?></lable>
667
- <input type="text" value="" id="sc-shortcode-model-text-link" style="width: 72%;padding: 5px;">
668
- <button class="button button-primary" id="sc-copy-shortcode-link"><span
669
- class="dashicons dashicons-admin-page"></span></button>
670
- </div>
671
- </main>
 
672
  </div>
673
  </div>
674
  </div>
675
- </div>
676
- <?php
677
- add_action('admin_footer', 'qsm_generate_quizzes_surveys_page_template');
678
  }
679
 
680
  /**
@@ -719,7 +727,7 @@ function qsm_set_screen_option( $status, $option, $value ) {
719
  *
720
  * @since 7.3.5
721
  */
722
- function qsm_generate_quizzes_surveys_page_template(){
723
  ?>
724
  <!-- Templates -->
725
  <script type="text/template" id="tmpl-no-quiz">
@@ -765,4 +773,4 @@ function qsm_generate_quizzes_surveys_page_template(){
765
  </script>
766
  <?php
767
  }
768
- ?>
24
  global $wpdb;
25
  global $mlwQuizMasterNext;
26
 
 
27
  // Delete quiz.
28
  if ( isset( $_POST['qsm_delete_quiz_nonce'], $_POST['delete_quiz_id'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['qsm_delete_quiz_nonce'] ) ), 'qsm_delete_quiz' ) ) {
29
+ $quiz_id = sanitize_text_field( wp_unslash( $_POST['delete_quiz_id'] ) );
30
+ $quiz_id = intval( str_replace( 'QID', '', $quiz_id ) );
31
+ do_action( 'qsm_before_delete_quiz', $quiz_id );
32
  $quiz_name = isset( $_POST['delete_quiz_name'] ) ? sanitize_text_field( wp_unslash( $_POST['delete_quiz_name'] ) ) : '';
33
  $mlwQuizMasterNext->quizCreator->delete_quiz( $quiz_id, $quiz_name );
34
  }
44
  // Resets stats for a quiz.
45
  if ( isset( $_POST['qsm_reset_stats_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['qsm_reset_stats_nonce'] ) ), 'qsm_reset_stats' ) ) {
46
  $quiz_id = isset( $_POST['reset_quiz_id'] ) ? intval( $_POST['reset_quiz_id'] ) : '';
47
+ $quiz_post_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = '$quiz_id'" );
48
+ if ( empty( $quiz_post_id ) || ! current_user_can( 'edit_post', $quiz_post_id ) ) {
49
+ $mlwQuizMasterNext->alertManager->newAlert( __( 'Sorry, you are not allowed to reset this quiz.', 'quiz-master-next' ), 'error' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  } else {
51
+ $results = $wpdb->update(
52
+ $wpdb->prefix . 'mlw_quizzes',
53
+ array(
54
+ 'quiz_views' => 0,
55
+ 'quiz_taken' => 0,
56
+ 'last_activity' => gmdate( 'Y-m-d H:i:s' ),
57
+ ),
58
+ array( 'quiz_id' => $quiz_id ),
59
+ array(
60
+ '%d',
61
+ '%d',
62
+ '%s',
63
+ ),
64
+ array( '%d' )
65
+ );
66
+ if ( false !== $results ) {
67
+ $mlwQuizMasterNext->alertManager->newAlert( __( 'The stats has been reset successfully.', 'quiz-master-next' ), 'success' );
68
+ $mlwQuizMasterNext->audit_manager->new_audit( 'Quiz Stats Have Been Reset', $quiz_id, '' );
69
+ } else {
70
+ $mlwQuizMasterNext->alertManager->newAlert( __( 'Error trying to reset stats. Please try again.', 'quiz-master-next' ), 'error' );
71
+ $mlwQuizMasterNext->log_manager->add( 'Error resetting stats', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' );
72
+ }
73
  }
74
  }
75
 
114
  $num_of_pages = ceil( $total / $limit );
115
  } else {
116
  $condition = ' WHERE deleted=0';
117
+ $condition = apply_filters( 'quiz_query_condition_clause', $condition );
118
+ $total = $wpdb->get_var( stripslashes( $wpdb->prepare( "SELECT COUNT(`quiz_id`) FROM {$wpdb->prefix}mlw_quizzes %1s", $condition ) ) );
119
  $num_of_pages = ceil( $total / $limit );
120
  }
121
 
155
  if ( isset( $_POST['btnSearchQuiz'] ) && isset( $_POST['s'] ) && ! empty( $_POST['s'] ) ) {
156
  $search_quiz = htmlspecialchars( sanitize_text_field( wp_unslash( $_POST['s'] ) ), ENT_QUOTES );
157
  $condition = " WHERE deleted=0 AND quiz_name LIKE '%$search_quiz%'";
158
+ $condition = apply_filters( 'quiz_query_condition_clause', $condition );
159
  $qry = stripslashes( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_quizzes%1s", $condition ) );
160
  $quizzes = $wpdb->get_results( $qry );
161
 
222
  $total_count = count( $quiz_json_array );
223
  wp_localize_script( 'qsm_admin_js', 'qsmQuizObject', $quiz_json_array );
224
  ?>
225
+ <div class="wrap qsm-quizes-page">
226
+ <h1>
227
+ <?php esc_html_e( 'Quizzes/Surveys', 'quiz-master-next' ); ?>
228
+ <a id="new_quiz_button" href="#" class="add-new-h2"><?php esc_html_e( 'Add New', 'quiz-master-next' ); ?></a>
229
+ </h1>
230
+ <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
231
+ <?php
232
+ if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  ?>
234
+ <div class="qsm-info-box">
235
+ <p><?php esc_html_e( 'Your site is using PHP version', 'quiz-master-next' ); ?>
236
+ <?php echo esc_html( PHP_VERSION ); ?>!
237
+ <?php esc_html_e( 'Starting in QSM 6.0, your version of PHP will no longer be supported.', 'quiz-master-next' ); ?>
238
+ <a href="https://quizandsurveymaster.com/increased-minimum-php-version-qsm-6-0/?utm_campaign=qsm_plugin&utm_medium=plugin&utm_source=minimum-php-notice" target="_blank"
239
+ rel="noopener"><?php esc_html_e( "Click here to learn more about QSM's minimum PHP version change.", 'quiz-master-next' ); ?></a>
 
 
 
 
 
 
 
 
 
 
240
  </p>
241
+ </div>
242
+ <?php
243
+ }
244
+ ?>
245
+ <form method="POST" id="posts-filter">
246
+ <?php wp_nonce_field( 'qsm_search_multiple_delete', 'qsm_search_multiple_delete_nonce' ); ?>
247
+ <div class="qsm-quizzes-page-content">
248
+ <div class="
249
+ <?php
250
+ if ( 'false' !== get_option( 'mlw_advert_shows' ) ) {
251
+ echo 'qsm-quiz-page-wrapper-with-ads';
252
+ } else {
253
+ echo 'qsm-quiz-page-wrapper';
254
+ }
255
+ ?>
256
+ ">
257
+ <p class="search-box">
258
+ <label class="screen-reader-text"
259
+ for="quiz_search"><?php esc_html_e( 'Search', 'quiz-master-next' ); ?></label>
260
+ <!-- Changed Request to Post -->
261
+ <input type="search" id="quiz_search" name="s"
262
+ value="<?php echo isset( $_POST['s'] ) && '' !== $_POST['s'] ? esc_attr( sanitize_text_field( wp_unslash( $_POST['s'] ) ) ) : ''; ?>">
263
+ <input id="search-submit" class="button" type="submit" name="btnSearchQuiz" value="Search Quiz">
264
+ <?php if ( class_exists( 'QSM_Export_Import' ) ) { ?>
265
+ <a class="button button-primary"
266
+ href="<?php echo esc_url( admin_url() . 'admin.php?page=qmn_addons&tab=export-and-import' ); ?>"
267
+ target="_blank" rel="noopener"><?php esc_html_e( 'Import & Export', 'quiz-master-next' ); ?></a>
268
+ <?php } else { ?>
269
+ <a id="show_import_export_popup" href="#" style="position: relative;top: 0px;"
270
+ class="add-new-h2 button-primary"><?php esc_html_e( 'Import & Export', 'quiz-master-next' ); ?></a>
271
+ <?php } ?>
272
+ </p>
273
+ <div class="tablenav top">
274
+ <div class="alignleft actions bulkactions">
275
+ <select id="bulk-action-top" name="qsm-ql-action-top">
276
+ <option selected="selected" value="none"><?php esc_html_e( 'Bulk Actions', 'quiz-master-next' ); ?>
277
+ </option>
278
+ <option value="delete_pr"><?php esc_html_e( 'Delete Permanently', 'quiz-master-next' ); ?></option>
279
+ </select>
280
+ <input id="bulk-submit" name="bulk-submit-top" class="button" type="button"
281
+ value="<?php esc_attr_e( 'Apply', 'quiz-master-next' ); ?>">
282
+ </div>
283
+ <div class="tablenav-pages">
284
+ <span
285
+ class="displaying-num"><?php echo esc_html( number_format_i18n( $total ) . ' ' . sprintf( _n( 'item', 'items', $total, 'quiz-master-next' ), number_format_i18n( $total ) ) ); ?></span>
286
+ <span class="pagination-links"
287
+ <?php
288
+ if ( (int) $num_of_pages <= 1 ) {
289
+ echo 'style="display:none;"';
290
+ }
291
+ ?>
292
+ >
293
+ <?php if ( '1' == $paged ) { ?>
294
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>
295
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>
296
+ <?php } else { ?>
297
+ <a class="first-page button"
298
+ href="<?php echo '?page=mlw_quiz_list&paged=1&s=' . esc_attr( $search ); ?>"
299
+ title="<?php esc_attr_e( 'Go to the first page', 'quiz-master-next' ); ?>">&laquo;</a>
300
+ <a class="prev-page button"
301
+ href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $prev_page ) . '&s=' . esc_attr( $search ); ?>"
302
+ title="<?php esc_attr_e( 'Go to the previous page', 'quiz-master-next' ); ?>">&lsaquo;</a>
303
+ <?php } ?>
304
+ <span class="paging-input">
305
+ <span class="total-pages"><?php echo esc_html( $paged ); ?></span>
306
+ <?php esc_html_e( 'of', 'quiz-master-next' ); ?>
307
+ <span class="total-pages"><?php echo esc_html( $num_of_pages ); ?></span>
308
+ </span>
309
+ <?php if ( $paged === $num_of_pages ) { ?>
310
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>
311
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>
312
+ <?php } else { ?>
313
+ <a class="next-page button"
314
+ href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $next_page ) . '&s=' . esc_attr( $search ); ?>"
315
+ title="<?php esc_attr_e( 'Go to the next page', 'quiz-master-next' ); ?>">&rsaquo;</a>
316
+ <a class="last-page button"
317
+ href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $num_of_pages ) . '&s=' . esc_attr( $search ); ?>"
318
+ title="<?php esc_attr_e( 'Go to the last page', 'quiz-master-next' ); ?>">&raquo;</a>
319
+ <?php } ?>
320
  </span>
321
+ </div>
 
 
 
 
 
 
 
 
 
 
 
322
  </div>
323
+ <table class="widefat">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  <?php
325
+ $orderby_slug = '&orderby=title&order=asc';
326
+ $orderby_date_slug = '&orderby=date&order=asc';
327
+ $orderby_class = $orderby_date_class = 'sortable desc';
328
+ // Title order
329
+ if ( isset( $_GET['orderby'] ) && sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) === 'title' ) {
330
+ if ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'asc' ) {
331
+ $orderby_slug = '&orderby=title&order=desc';
332
+ $orderby_class = 'sorted asc';
333
+ } elseif ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'desc' ) {
334
+ $orderby_slug = '&orderby=title&order=asc';
335
+ $orderby_class = 'sorted desc';
336
+ }
337
+ } elseif ( isset( $_GET['orderby'] ) && sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) === 'date' ) {
338
+ if ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'asc' ) {
339
+ $orderby_date_slug = '&orderby=date&order=desc';
340
+ $orderby_date_class = 'sorted asc';
341
+ } elseif ( isset( $_GET['order'] ) && sanitize_text_field( wp_unslash( $_GET['order'] ) ) === 'desc' ) {
342
+ $orderby_date_slug = '&orderby=date&order=asc';
343
+ $orderby_date_class = 'sorted desc';
344
  }
 
 
 
 
 
 
 
 
345
  }
346
  ?>
347
+ <thead>
348
+ <tr>
349
+ <td class="manage-column column-cb check-column" id="cb"><input type="checkbox"
350
+ name="delete-all-shortcodes-1" id="delete-all-shortcodes-1" value="0"></td>
351
+ <th class="<?php echo esc_attr( $orderby_class ); ?>">
352
+ <?php
353
+ $paged_slug = isset( $_GET['paged'] ) && '' !== $_GET['paged'] ? '&paged=' . sanitize_text_field( wp_unslash( $_GET['paged'] ) ) : '';
354
+ $searched_slug = isset( $_GET['s'] ) && '' !== $_GET['s'] ? '&s=' . sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '';
355
+ $sorting_url = '?page=mlw_quiz_list' . $paged_slug . $searched_slug;
356
+ ?>
357
+ <a href="<?php echo esc_url( $sorting_url . $orderby_slug ); ?>">
358
+ <span><?php esc_html_e( 'Title', 'quiz-master-next' ); ?></span>
359
+ <span class="sorting-indicator"></span>
360
+ </a>
361
+ </th>
362
+ <th><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></th>
363
+ <th><?php esc_html_e( 'Views', 'quiz-master-next' ); ?></th>
364
+ <th><?php esc_html_e( 'Participants', 'quiz-master-next' ); ?></th>
365
+ <th class="<?php echo esc_attr( $orderby_date_class ); ?>">
366
+ <a href="<?php echo esc_url( $sorting_url . $orderby_date_slug ); ?>">
367
+ <span><?php esc_html_e( 'Last Modified', 'quiz-master-next' ); ?></span>
368
+ <span class="sorting-indicator"></span>
369
+ </a>
370
+ </th>
371
+ </tr>
372
+ </thead>
373
+ <tbody id="the-list">
374
+ <?php
375
+ if ( $quiz_json_array ) {
376
+ foreach ( $quiz_json_array as $key => $single_arr ) {
377
+ ?>
378
+ <tr class="qsm-quiz-row" data-id="<?php echo esc_attr( $single_arr['id'] ); ?>">
379
+ <th class="check-column">
380
+ <input type="checkbox" class="chk_remove_all" name="chk_remove_all[]"
381
+ id="chk_remove_all" value="<?php echo esc_attr( $single_arr['id'] ); ?>">
382
+ </th>
383
+ <td class="post-title column-title">
384
+ <a class="row-title" href="admin.php?page=mlw_quiz_options&&quiz_id=<?php echo esc_attr( $single_arr['id'] ); ?>" aria-label="<?php echo esc_attr( $single_arr['name'] ); ?>"><?php echo esc_html( $single_arr['name'] ); ?> <strong style="color: #222; text-transform: capitalize;"><?php echo esc_html( 'publish' !== $single_arr['post_status'] ? '— ' . $single_arr['post_status'] : '' ); ?></strong>
385
+ </a>
386
+ <div class="row-actions">
387
+ <a class="qsm-action-link" href="admin.php?page=mlw_quiz_options&&quiz_id=<?php echo esc_attr( $single_arr['id'] ); ?>"><?php esc_html_e( 'Edit', 'quiz-master-next' ); ?></a> |
388
+ <a class="qsm-action-link qsm-action-link-duplicate" href="#"><?php esc_html_e( 'Duplicate', 'quiz-master-next' ); ?></a> |
389
+ <a class="qsm-action-link qsm-action-link-delete" href="#"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></a> |
390
+ <a class="qsm-action-link" href="admin.php?page=mlw_quiz_results&quiz_id=<?php echo esc_attr( $single_arr['id'] ); ?>"><?php esc_html_e( 'View Results', 'quiz-master-next' ); ?></a> |
391
+ <a class="qsm-action-link" target="_blank" rel="noopener" href="<?php echo esc_url( $single_arr['link'] ); ?>"><?php esc_html_e( 'Preview', 'quiz-master-next' ); ?></a>
392
+ </div>
393
+ </td>
394
+ <td>
395
+ <a href="#" class="qsm-list-shortcode-view">
396
+ <span class="dashicons dashicons-welcome-view-site"></span>
397
+ </a>
398
+ <div class="sc-content sc-embed">[qsm quiz=<?php echo esc_attr( $single_arr['id'] ); ?>]</div>
399
+ <div class="sc-content sc-link">[qsm_link id=<?php echo esc_attr( $single_arr['id'] ); ?>]<?php esc_html_e( 'Click here', 'quiz-master-next' ); ?>[/qsm_link]
400
+ </div>
401
+ </td>
402
+ <td>
403
+ <?php echo esc_html( $single_arr['views'] ); ?>
404
+ <div class="row-actions">
405
+ <a class="qsm-action-link qsm-action-link-reset"
406
+ href="#"><?php esc_html_e( 'Reset', 'quiz-master-next' ); ?></a>
407
+ </div>
408
+ </td>
409
+ <td class="comments column-comments" style="text-align: left;">
410
+ <span class="post-com-count post-com-count-approved">
411
+ <span class="comment-count-approved" aria-hidden="true"><?php echo esc_html( $single_arr['taken'] ); ?></span>
412
+ <span class="screen-reader-text"><?php echo esc_html( $single_arr['taken'] . __( 'Participants', 'quiz-master-next' ) ); ?></span>
413
+ </span>
414
+ </td>
415
+ <td>
416
+ <abbr title="<?php echo esc_html( $single_arr['lastActivityDateTime'] ); ?>"><?php echo esc_html( $single_arr['lastActivity'] ); ?></abbr>
417
+ </td>
418
+ </tr>
419
+ <?php
420
+ }
421
+ } else {
422
+ ?>
423
+ <tr>
424
+ <td colspan="6" style="text-align: center;">
425
+ <?php esc_html_e( 'No Quiz found!', 'quiz-master-next' ); ?>
426
+ </td>
427
+ </tr>
428
+ <?php
429
+ }
430
+ ?>
431
+ </tbody>
432
+ <tfoot>
433
+ <tr>
434
+ <td class="manage-column column-cb check-column" id="cb"><input type="checkbox"
435
+ name="delete-all-shortcodes-2" id="delete-all-shortcodes-2" value="0"></td>
436
+ <th class="<?php echo esc_attr( $orderby_class ); ?>" scope="col">
437
+ <a href="<?php echo esc_url( $sorting_url . $orderby_slug ); ?>">
438
+ <span><?php esc_html_e( 'Title', 'quiz-master-next' ); ?></span>
439
+ <span class="sorting-indicator"></span>
440
+ </a>
441
+ </th>
442
+ <th><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></th>
443
+ <th><?php esc_html_e( 'Views', 'quiz-master-next' ); ?></th>
444
+ <th><?php esc_html_e( 'Participants', 'quiz-master-next' ); ?></th>
445
+ <th class="<?php echo esc_attr( $orderby_date_class ); ?>" scope="col">
446
+ <a href="<?php echo esc_url( $sorting_url . $orderby_date_slug ); ?>">
447
+ <span><?php esc_html_e( 'Last Modified', 'quiz-master-next' ); ?></span>
448
+ <span class="sorting-indicator"></span>
449
+ </a>
450
+ </th>
451
+ </tr>
452
+ </tfoot>
453
+ </table>
454
+ <div class="tablenav bottom">
455
+ <select id="bulk-action-bottom" name="qsm-ql-action-bottom">
456
+ <option selected="selected" value="none"><?php esc_html_e( 'Bulk Actions', 'quiz-master-next' ); ?>
457
+ </option>
458
+ <option value="delete_pr"><?php esc_html_e( 'Delete Permanently', 'quiz-master-next' ); ?></option>
459
+ </select>
460
+ <input id="bulk-submit" name="bulk-submit-bottom" class="button" type="button"
461
+ value="<?php esc_attr_e( 'Apply', 'quiz-master-next' ); ?>">
462
+ <div class="tablenav-pages">
463
+ <span
464
+ class="displaying-num"><?php echo esc_html( number_format_i18n( $total ) . ' ' . sprintf( _n( 'item', 'items', $total, 'quiz-master-next' ), number_format_i18n( $total ) ) ); ?></span>
465
+ <span class="pagination-links"
466
+ <?php
467
+ if ( (int) $num_of_pages <= 1 ) {
468
+ echo 'style="display:none;"';
469
+ }
470
+ ?>
471
+ >
472
+ <?php if ( '1' == $paged ) { ?>
473
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>
474
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>
475
+ <?php } else { ?>
476
+ <a class="first-page button"
477
+ href="<?php echo '?page=mlw_quiz_list&paged=1&s=' . esc_attr( $search ); ?>"
478
+ title="<?php esc_attr_e( 'Go to the first page', 'quiz-master-next' ); ?>">&laquo;</a>
479
+ <a class="prev-page button"
480
+ href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $prev_page ) . '&s=' . esc_attr( $search ); ?>"
481
+ title="<?php esc_attr_e( 'Go to the previous page', 'quiz-master-next' ); ?>">&lsaquo;</a>
482
+ <?php } ?>
483
+ <span class="paging-input">
484
+ <span class="total-pages"><?php echo esc_html( $paged ); ?></span>
485
+ <?php esc_html_e( 'of', 'quiz-master-next' ); ?>
486
+ <span class="total-pages"><?php echo esc_html( $num_of_pages ); ?></span>
487
+ </span>
488
+ <?php if ( $paged === $num_of_pages ) { ?>
489
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>
490
+ <span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>
491
+ <?php } else { ?>
492
+ <a class="next-page button"
493
+ href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $next_page ) . '&s=' . esc_attr( $search ); ?>"
494
+ title="<?php esc_attr_e( 'Go to the next page', 'quiz-master-next' ); ?>">&rsaquo;</a>
495
+ <a class="last-page button"
496
+ href="<?php echo '?page=mlw_quiz_list&paged=' . esc_attr( $num_of_pages ) . '&s=' . esc_attr( $search ); ?>"
497
+ title="<?php esc_attr_e( 'Go to the last page', 'quiz-master-next' ); ?>">&raquo;</a>
498
+ <?php } ?>
499
  </span>
500
+ </div>
 
 
 
 
 
 
 
 
 
 
 
501
  </div>
502
  </div>
503
  </div>
504
+ </form>
505
+
506
+ <!-- Popup for resetting stats -->
507
+ <div class="qsm-popup qsm-popup-slide" id="modal-1" aria-hidden="true">
508
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
509
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
510
+ <header class="qsm-popup__header">
511
+ <h2 class="qsm-popup__title" id="modal-1-title">
512
+ <?php esc_html_e( 'Reset stats for this quiz?', 'quiz-master-next' ); ?></h2>
513
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
514
+ </header>
515
+ <main class="qsm-popup__content" id="modal-1-content">
516
+ <p><?php esc_html_e( 'Are you sure you want to reset the stats to 0? All views and taken stats for this quiz will be reset. This is permanent and cannot be undone.', 'quiz-master-next' ); ?>
517
+ </p>
518
+ <form action="" method="post" id="reset_quiz_form">
519
+ <?php wp_nonce_field( 'qsm_reset_stats', 'qsm_reset_stats_nonce' ); ?>
520
+ <input type="hidden" id="reset_quiz_id" name="reset_quiz_id" value="0" />
521
+ </form>
522
+ </main>
523
+ <footer class="qsm-popup__footer">
524
+ <button id="reset-stats-button"
525
+ class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Reset All Stats For Quiz', 'quiz-master-next' ); ?></button>
526
+ <button class="qsm-popup__btn" data-micromodal-close
527
+ aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
528
+ </footer>
529
+ </div>
530
  </div>
531
  </div>
 
532
 
533
+ <!-- Popup for new quiz -->
534
+ <?php qsm_create_new_quiz_wizard(); ?>
535
+
536
+ <!-- Popup for duplicate quiz -->
537
+ <div class="qsm-popup qsm-popup-slide" id="modal-4" aria-hidden="true">
538
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
539
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-4-title">
540
+ <header class="qsm-popup__header">
541
+ <h2 class="qsm-popup__title" id="modal-4-title"><?php esc_html_e( 'Duplicate', 'quiz-master-next' ); ?></h2>
542
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
543
+ </header>
544
+ <main class="qsm-popup__content" id="modal-4-content">
545
+ <form action='' method='post' id="duplicate-quiz-form">
546
+ <label
547
+ for="duplicate_questions"><?php esc_html_e( 'Duplicate questions also?', 'quiz-master-next' ); ?></label><input
548
+ type="checkbox" name="duplicate_questions" id="duplicate_questions" /><br />
549
+ <br />
550
+ <label
551
+ for="duplicate_new_quiz_name"><?php esc_html_e( 'Name Of New Quiz Or Survey:', 'quiz-master-next' ); ?></label><input
552
+ type="text" id="duplicate_new_quiz_name" name="duplicate_new_quiz_name" />
553
+ <input type="hidden" id="duplicate_quiz_id" name="duplicate_quiz_id" />
554
+ <?php wp_nonce_field( 'qsm_duplicate_quiz', 'qsm_duplicate_quiz_nonce' ); ?>
555
+ </form>
556
+ </main>
557
+ <footer class="qsm-popup__footer">
558
+ <button id="duplicate-quiz-button"
559
+ class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Duplicate', 'quiz-master-next' ); ?></button>
560
+ <button class="qsm-popup__btn" data-micromodal-close
561
+ aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
562
+ </footer>
563
+ </div>
564
  </div>
565
  </div>
 
566
 
567
+ <!-- Popup for delete quiz -->
568
+ <div class="qsm-popup qsm-popup-slide" id="modal-5" aria-hidden="true">
569
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
570
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
571
+ <header class="qsm-popup__header">
572
+ <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></h2>
573
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
574
+ </header>
575
+ <main class="qsm-popup__content" id="modal-5-content">
576
+ <form action='' method='post' id="delete-quiz-form" style="display:flex; flex-direction:column;">
577
+ <h3><b><?php esc_html_e( 'Are you sure you want to delete this quiz or survey?', 'quiz-master-next' ); ?></b>
578
+ </h3>
579
+ <label>
580
+ <input type="checkbox" value="1" name="qsm_delete_question_from_qb" />
581
+ <?php esc_html_e( 'Delete question from question bank?', 'quiz-master-next' ); ?>
582
+ </label>
583
+ <label>
584
+ <input type="checkbox" name="qsm_delete_from_db" value="1"/>
585
+ <?php esc_html_e( 'Delete items from database?', 'quiz-master-next' ); ?>
586
+ </label>
587
+ <?php wp_nonce_field( 'qsm_delete_quiz', 'qsm_delete_quiz_nonce' ); ?>
588
+ <input type='hidden' id='delete_quiz_id' name='delete_quiz_id' value='' />
589
+ <input type='hidden' id='delete_quiz_name' name='delete_quiz_name' value='' />
590
+ </form>
591
+ </main>
592
+ <footer class="qsm-popup__footer">
593
+ <button id="delete-quiz-button"
594
+ class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></button>
595
+ <button class="qsm-popup__btn" data-micromodal-close
596
+ aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
597
+ </footer>
598
+ </div>
599
  </div>
600
  </div>
601
+ <!-- Popup for bulk delete quiz -->
602
+ <div class="qsm-popup qsm-popup-slide" id="modal-bulk-delete" aria-hidden="true">
603
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
604
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
605
+ <header class="qsm-popup__header">
606
+ <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Bulk Delete', 'quiz-master-next' ); ?></h2>
607
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
608
+ </header>
609
+ <main class="qsm-popup__content" id="modal-5-content">
610
+ <form action='' method='post' id="bult-delete-quiz-form" style="display:flex; flex-direction:column;">
611
+ <h3><b><?php esc_html_e( 'Are you sure you want to delete selected quiz or survey?', 'quiz-master-next' ); ?></b>
612
+ </h3>
613
+ <label>
614
+ <input type="checkbox" name="qsm_delete_question_from_qb" checked="checked" />
615
+ <?php esc_html_e( 'Delete question from question bank?', 'quiz-master-next' ); ?>
616
+ </label>
617
+ <label>
618
+ <input type="checkbox" name="qsm_delete_from_db" />
619
+ <?php esc_html_e( 'Delete items from database?', 'quiz-master-next' ); ?>
620
+ </label>
621
+ </form>
622
+ </main>
623
+ <footer class="qsm-popup__footer">
624
+ <button id="bulk-delete-quiz-button"
625
+ class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></button>
626
+ <button class="qsm-popup__btn" data-micromodal-close
627
+ aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
628
+ </footer>
629
+ </div>
630
  </div>
631
  </div>
 
632
 
633
 
634
+ <!-- Popup for export import upsell -->
635
+ <div class="qsm-popup qsm-popup-slide" id="modal-export-import" aria-hidden="true">
636
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
637
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
638
+ <header class="qsm-popup__header">
639
+ <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Extend QSM', 'quiz-master-next' ); ?>
640
+ </h2>
641
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
642
+ </header>
643
+ <main class="qsm-popup__content" id="modal-5-content">
644
+ <h3><b><?php esc_html_e( 'Export functionality is provided as Premium addon.', 'quiz-master-next' ); ?></b>
645
+ </h3>
646
+ </main>
647
+ <footer class="qsm-popup__footer">
648
+ <a style="color: white; text-decoration: none;"
649
+ href="https://quizandsurveymaster.com/downloads/export-import/" target="_blank"
650
+ class="qsm-popup__btn qsm-popup__btn-primary"><?php esc_html_e( 'Buy Now', 'quiz-master-next' ); ?></a>
651
+ <button class="qsm-popup__btn" data-micromodal-close
652
+ aria-label="Close this dialog window"><?php esc_html_e( 'Cancel', 'quiz-master-next' ); ?></button>
653
+ </footer>
654
+ </div>
655
  </div>
656
  </div>
 
657
 
658
+ <!-- Popup for delete quiz -->
659
+ <div class="qsm-popup qsm-popup-slide" id="modal-6" aria-hidden="true">
660
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
661
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-5-title">
662
+ <header class="qsm-popup__header">
663
+ <h2 class="qsm-popup__title" id="modal-5-title"><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></h2>
664
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
665
+ </header>
666
+ <main class="qsm-popup__content" id="modal-5-content">
667
+ <div class="qsm-row" style="margin-bottom: 30px;">
668
+ <lable><?php esc_html_e( 'Embed Shortcode', 'quiz-master-next' ); ?></lable>
669
+ <input type="text" value="" id="sc-shortcode-model-text" style="width: 72%;padding: 5px;">
670
+ <button class="button button-primary" id="sc-copy-shortcode"><span
671
+ class="dashicons dashicons-admin-page"></span></button>
672
+ </div>
673
+ <div class="qsm-row">
674
+ <lable><?php esc_html_e( 'Link Shortcode', 'quiz-master-next' ); ?></lable>
675
+ <input type="text" value="" id="sc-shortcode-model-text-link" style="width: 72%;padding: 5px;">
676
+ <button class="button button-primary" id="sc-copy-shortcode-link"><span
677
+ class="dashicons dashicons-admin-page"></span></button>
678
+ </div>
679
+ </main>
680
+ </div>
681
  </div>
682
  </div>
683
  </div>
684
+ <?php
685
+ add_action( 'admin_footer', 'qsm_generate_quizzes_surveys_page_template' );
 
686
  }
687
 
688
  /**
727
  *
728
  * @since 7.3.5
729
  */
730
+ function qsm_generate_quizzes_surveys_page_template() {
731
  ?>
732
  <!-- Templates -->
733
  <script type="text/template" id="tmpl-no-quiz">
773
  </script>
774
  <?php
775
  }
776
+ ?>
php/admin/tools-page.php CHANGED
@@ -21,20 +21,20 @@ function qsm_generate_quiz_tools() {
21
  add_meta_box( 'qsm_restore_box', 'Restore Quiz', 'qsm_restore_function', 'quiz_wpss' );
22
  add_meta_box( 'qsm_audit_box', 'Audit Trail', 'qsm_audit_box', 'quiz_wpss' );
23
  ?>
24
- <style type="text/css">
25
- #qsm_restore_box .hndle,
26
- #qsm_audit_box .hndle{
27
- padding-left: 15px;
28
- padding-bottom: 0;
29
- }
30
- .qsm-tools-page .handle-order-higher,
31
- .qsm-tools-page .handle-order-lower,
32
- .qsm-tools-page .handle-actions{
33
- display: none;
34
- }
35
- </style>
36
  <div class="wrap qsm-tools-page">
37
- <h2><?php esc_html_e('Tools', 'quiz-master-next'); ?></h2>
38
 
39
  <div style="float:left; width:100%;" class="inner-sidebar1">
40
  <?php do_meta_boxes( 'quiz_wpss', 'advanced', null ); ?>
@@ -60,7 +60,7 @@ function qsm_restore_function() {
60
  // Checks if form was submitted.
61
  if ( isset( $_POST['restore_quiz'] ) ) {
62
  $restore = $wpdb->update(
63
- $wpdb->prefix.'mlw_quizzes',
64
  array(
65
  'deleted' => 0,
66
  ),
@@ -80,11 +80,13 @@ function qsm_restore_function() {
80
  <?php
81
  } else {
82
  // Restores the quiz post type for the quiz.
83
- $my_query = new WP_Query( array(
84
- 'post_type' => 'qsm_quiz',
85
- 'meta_key' => 'quiz_id',
86
- 'meta_value' => intval( $_POST['restore_quiz'] ),
87
- ));
 
 
88
  if ( $my_query->have_posts() ) {
89
  while ( $my_query->have_posts() ) {
90
  $my_query->the_post();
@@ -140,44 +142,55 @@ function qsm_audit_box() {
140
  $begin = 0;
141
  }
142
  $left = $audit_total - ( $page * $table_limit );
143
- $audit_trails = $wpdb->get_results( $wpdb->prepare( "SELECT trail_id, action_user, action, time
144
- FROM {$wpdb->prefix}mlw_qm_audit_trail ORDER BY trail_id DESC LIMIT %d, %d", $begin, $table_limit ) );
145
  ?>
146
- <p><?php esc_html_e('Total actions since QSM installed:', 'quiz-master-next'); ?> <?php echo esc_html( $audit_total ); ?></p>
 
 
 
 
147
  <?php
148
 
149
  // Determine which navigation to show.
150
  if ( $page > 0 ) {
151
  $previous = $page - 2;
152
  ?>
153
- <a class="button" id="prev_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr($previous); ?>">
154
- <?php /* translators: %s: table limit */
155
- echo sprintf( esc_html__( 'Previous %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) ); ?>
 
 
156
  </a>
157
  <?php
158
  if ( $left > $table_limit ) {
159
  ?>
160
- <a class="button" id="next_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr($page); ?>">
161
- <?php /* translators: %s: table limit */
162
- echo sprintf( esc_html__( 'Next %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) ); ?>
 
 
163
  </a>
164
  <?php
165
  }
166
  } elseif ( 0 == $page ) {
167
  if ( $left > $table_limit ) {
168
  ?>
169
- <a class="button" id="next_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr($page); ?>">
170
- <?php /* translators: %s: table limit */
171
- echo sprintf( esc_html__( 'Next %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) ); ?>
 
 
172
  </a>
173
  <?php
174
  }
175
  } elseif ( $left < $table_limit ) {
176
  $previous = $page - 2;
177
  ?>
178
- <a class="button" id="prev_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr($previous); ?>">
179
- <?php /* translators: %s: table limit */
180
- echo sprintf( esc_html__( 'Previous %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) ); ?>
 
 
181
  </a>
182
  <?php
183
  }
@@ -185,32 +198,73 @@ function qsm_audit_box() {
185
  <table class=widefat>
186
  <thead>
187
  <tr>
188
- <th>ID</th>
189
  <th><?php esc_html_e( 'User', 'quiz-master-next' ); ?></th>
190
  <th><?php esc_html_e( 'Action', 'quiz-master-next' ); ?></th>
 
191
  <th><?php esc_html_e( 'Time', 'quiz-master-next' ); ?></th>
192
  </tr>
193
  </thead>
194
  <tbody id="the-list">
195
  <?php
 
 
 
 
 
 
 
196
  $alternate = '';
197
- foreach ( $audit_trails as $audit ) {
198
- if ( $alternate ) {
199
- $alternate = '';
200
- } else {
201
- $alternate = 'alternate';
202
- } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  <tr class="<?php echo esc_attr( $alternate ); ?>">
204
- <td><?php echo esc_html( $audit->trail_id ); ?></td>
205
- <td><?php echo esc_html( $audit->action_user ); ?></td>
206
- <td><?php echo esc_html( $audit->action ); ?></td>
207
- <td><?php echo esc_html( $audit->time ); ?></td>
208
  </tr>
209
  <?php
210
  }
 
211
  ?>
212
  </tbody>
213
  </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  <?php
215
  }
216
  ?>
21
  add_meta_box( 'qsm_restore_box', 'Restore Quiz', 'qsm_restore_function', 'quiz_wpss' );
22
  add_meta_box( 'qsm_audit_box', 'Audit Trail', 'qsm_audit_box', 'quiz_wpss' );
23
  ?>
24
+ <style type="text/css">
25
+ #qsm_restore_box .hndle,
26
+ #qsm_audit_box .hndle{
27
+ padding-left: 15px;
28
+ padding-bottom: 0;
29
+ }
30
+ .qsm-tools-page .handle-order-higher,
31
+ .qsm-tools-page .handle-order-lower,
32
+ .qsm-tools-page .handle-actions{
33
+ display: none;
34
+ }
35
+ </style>
36
  <div class="wrap qsm-tools-page">
37
+ <h2><?php esc_html_e( 'Tools', 'quiz-master-next' ); ?></h2>
38
 
39
  <div style="float:left; width:100%;" class="inner-sidebar1">
40
  <?php do_meta_boxes( 'quiz_wpss', 'advanced', null ); ?>
60
  // Checks if form was submitted.
61
  if ( isset( $_POST['restore_quiz'] ) ) {
62
  $restore = $wpdb->update(
63
+ $wpdb->prefix . 'mlw_quizzes',
64
  array(
65
  'deleted' => 0,
66
  ),
80
  <?php
81
  } else {
82
  // Restores the quiz post type for the quiz.
83
+ $my_query = new WP_Query(
84
+ array(
85
+ 'post_type' => 'qsm_quiz',
86
+ 'meta_key' => 'quiz_id',
87
+ 'meta_value' => intval( $_POST['restore_quiz'] ),
88
+ )
89
+ );
90
  if ( $my_query->have_posts() ) {
91
  while ( $my_query->have_posts() ) {
92
  $my_query->the_post();
142
  $begin = 0;
143
  }
144
  $left = $audit_total - ( $page * $table_limit );
145
+ $audit_trails = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_qm_audit_trail ORDER BY trail_id DESC LIMIT %d, %d", $begin, $table_limit ) );
 
146
  ?>
147
+ <div class="audit_buttons">
148
+ <p><?php esc_html_e( 'Total actions since QSM installed:', 'quiz-master-next' ); ?> <?php echo esc_html( $audit_total ); ?></p>
149
+ <p><a class='button button-primary btn_export' id="btn_export" title='Export' ><?php esc_html_e( 'Export', 'quiz-master-next' ); ?></a>
150
+ <a class='button button-primary btn_clear_logs' id="btn_clear_logs" title='Clear Logs' ><?php esc_html_e( 'Clear Audit', 'quiz-master-next' ); ?></a></p>
151
+ </div>
152
  <?php
153
 
154
  // Determine which navigation to show.
155
  if ( $page > 0 ) {
156
  $previous = $page - 2;
157
  ?>
158
+ <a class="button" id="prev_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr( $previous ); ?>">
159
+ <?php
160
+ /* translators: %s: table limit */
161
+ echo sprintf( esc_html__( 'Previous %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) );
162
+ ?>
163
  </a>
164
  <?php
165
  if ( $left > $table_limit ) {
166
  ?>
167
+ <a class="button" id="next_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr( $page ); ?>">
168
+ <?php
169
+ /* translators: %s: table limit */
170
+ echo sprintf( esc_html__( 'Next %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) );
171
+ ?>
172
  </a>
173
  <?php
174
  }
175
  } elseif ( 0 == $page ) {
176
  if ( $left > $table_limit ) {
177
  ?>
178
+ <a class="button" id="next_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr( $page ); ?>">
179
+ <?php
180
+ /* translators: %s: table limit */
181
+ echo sprintf( esc_html__( 'Next %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) );
182
+ ?>
183
  </a>
184
  <?php
185
  }
186
  } elseif ( $left < $table_limit ) {
187
  $previous = $page - 2;
188
  ?>
189
+ <a class="button" id="prev_page" href="?page=qsm_quiz_tools&&audit_page=<?php echo esc_attr( $previous ); ?>">
190
+ <?php
191
+ /* translators: %s: table limit */
192
+ echo sprintf( esc_html__( 'Previous %s Audits', 'quiz-master-next' ), esc_html( $table_limit ) );
193
+ ?>
194
  </a>
195
  <?php
196
  }
198
  <table class=widefat>
199
  <thead>
200
  <tr>
201
+ <th><?php esc_html_e( 'ID', 'quiz-master-next' ); ?></th>
202
  <th><?php esc_html_e( 'User', 'quiz-master-next' ); ?></th>
203
  <th><?php esc_html_e( 'Action', 'quiz-master-next' ); ?></th>
204
+ <th id="quiz_name"><?php esc_html_e( 'Quiz Name', 'quiz-master-next' ); ?></th>
205
  <th><?php esc_html_e( 'Time', 'quiz-master-next' ); ?></th>
206
  </tr>
207
  </thead>
208
  <tbody id="the-list">
209
  <?php
210
+ wp_localize_script(
211
+ 'qsm_admin_js',
212
+ 'qsm_logs_delete',
213
+ array(
214
+ 'qsm_delete_audit_logs' => esc_html__( 'Are you sure you want to delete this record? You will not be able to recover this data!', 'quiz-master-next' ),
215
+ )
216
+ );
217
  $alternate = '';
218
+ if ( ! empty( $audit_trails ) ) {
219
+ foreach ( $audit_trails as $audit ) {
220
+ if ( $alternate ) {
221
+ $alternate = '';
222
+ } else {
223
+ $alternate = 'alternate';
224
+ }
225
+ ?>
226
+ <tr class="<?php echo esc_attr( $alternate ); ?>">
227
+ <td><?php echo esc_html( $audit->trail_id ); ?></td>
228
+ <td><?php echo esc_html( $audit->action_user ); ?></td>
229
+ <td>
230
+ <?php if ( ! empty( $audit->form_data ) ) { ?>
231
+ <a href="#" class="qsm_audit_data" data-auditid="<?php echo esc_html( $audit->form_data ); ?>"><?php echo esc_html( $audit->action ); ?></a>
232
+ <?php
233
+ } else {
234
+ echo esc_html( $audit->action );
235
+ }
236
+ ?>
237
+ </td>
238
+ <td><?php echo esc_html( $audit->quiz_name ); ?> [ <strong>ID:</strong> <?php echo esc_html( $audit->quiz_id ); ?> ] </td>
239
+ <td><?php echo esc_html( $audit->time ); ?></td>
240
+ </tr>
241
+ <?php
242
+ }
243
+ } else {
244
+ ?>
245
  <tr class="<?php echo esc_attr( $alternate ); ?>">
246
+ <td colspan="5">No data found!!</td>
 
 
 
247
  </tr>
248
  <?php
249
  }
250
+
251
  ?>
252
  </tbody>
253
  </table>
254
+ <div class="qsm-popup qsm-popup-slide" id="qsm_fetch_audit_data" aria-hidden="true">
255
+ <div class="qsm-popup__overlay" tabindex="-1" data-micromodal-close>
256
+ <div class="qsm-popup__container" role="dialog" aria-modal="true" aria-labelledby="modal-2-title">
257
+ <header class="qsm-popup__header">
258
+ <h3 class="qsm-popup__title" id="modal-2-title">
259
+ <?php esc_html_e( 'Settings', 'quiz-master-next' ); ?></h3>
260
+ <a class="qsm-popup__close" aria-label="Close modal" data-micromodal-close></a>
261
+ </header>
262
+ <div class="qsm_setting__data">
263
+ <p></p>
264
+ </div>
265
+ </div>
266
+ </div>
267
+ </div>
268
  <?php
269
  }
270
  ?>
php/classes/class-qmn-alert-manager.php CHANGED
@@ -42,5 +42,15 @@ class MlwQmnAlertManager {
42
  echo apply_filters( 'qsm_alert_messages', $alert_list );
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
 
42
  echo apply_filters( 'qsm_alert_messages', $alert_list );
43
  }
44
 
45
+ public function showWarnings() {
46
+ $alert_list = "";
47
+ foreach ( $this->alerts as $alert ) {
48
+ if ( "warning" === $alert['type'] ) {
49
+ $alert_list .= "<div class=\"notice notice-warning \"><p><strong>".__('Warning!', 'quiz-master-next')." </strong>".$alert["message"]."</p></div>";
50
+ }
51
+ }
52
+ echo apply_filters( 'qsm_warning_messages', $alert_list );
53
+ }
54
+
55
  }
56
 
php/classes/class-qmn-plugin-helper.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- exit;
4
  }
5
 
6
  /**
@@ -10,644 +10,650 @@ if ( ! defined('ABSPATH') ) {
10
  *
11
  * @since 4.0.0
12
  */
13
- class QMNPluginHelper
14
- {
15
-
16
- /**
17
- * Addon Page tabs array
18
- *
19
- * @var array
20
- * @since 4.0.0
21
- */
22
- public $addon_tabs = array();
23
-
24
- /**
25
- * Stats Page tabs array
26
- *
27
- * @var array
28
- * @since 4.0.0
29
- */
30
- public $stats_tabs = array();
31
-
32
- /**
33
- * Admin Results Page tabs array
34
- *
35
- * @var array
36
- * @since 5.0.0
37
- */
38
- public $admin_results_tabs = array();
39
-
40
- /**
41
- * Results Details Page tabs array
42
- *
43
- * @var array
44
- * @since 4.1.0
45
- */
46
- public $results_tabs = array();
47
-
48
- /**
49
- * Settings Page tabs array
50
- *
51
- * @var array
52
- * @since 4.0.0
53
- */
54
- public $settings_tabs = array();
55
-
56
- /**
57
- * Question types array
58
- *
59
- * @var array
60
- * @since 4.0.0
61
- */
62
- public $question_types = array();
63
-
64
- /**
65
- * Template array
66
- *
67
- * @var array
68
- * @since 4.5.0
69
- */
70
- public $quiz_templates = array();
71
-
72
- /**
73
- * Main Construct Function
74
- *
75
- * Call functions within class
76
- *
77
- * @since 4.0.0
78
- * @return void
79
- */
80
- public function __construct() {
81
- add_action('wp_ajax_qmn_question_type_change', array( $this, 'get_question_type_edit_content' ));
82
- }
83
-
84
- /**
85
- * Calls all class functions to initialize quiz
86
- *
87
- * @param int $quiz_id The ID of the quiz or survey to load.
88
- * @return bool True or False if ID is valid.
89
- */
90
- public function prepare_quiz( $quiz_id ) {
91
- $quiz_id = intval($quiz_id);
92
-
93
- // Tries to load quiz name to ensure this is a valid ID.
94
- global $wpdb;
95
- $quiz_name = $wpdb->get_var($wpdb->prepare("SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $quiz_id));
96
- if ( is_null($quiz_name) ) {
97
- return false;
98
- }
99
-
100
- global $mlwQuizMasterNext;
101
- $mlwQuizMasterNext->quizCreator->set_id($quiz_id);
102
- $mlwQuizMasterNext->quiz_settings->prepare_quiz($quiz_id);
103
-
104
- return true;
105
- }
106
-
107
- /**
108
- * Retrieves all quizzes.
109
- *
110
- * @param bool $include_deleted If set to true, returned array will include all deleted quizzes
111
- * @param string $order_by The column the quizzes should be ordered by
112
- * @param string $order whether the $order_by should be ordered as ascending or decending. Can be "ASC" or "DESC"
113
- * @param arr $user_role role of current user
114
- * @param int $user_id Get the quiz based on user id
115
- * @return array All of the quizzes as a numerical array of objects
116
- */
117
- public function get_quizzes( $include_deleted = false, $order_by = 'quiz_id', $order = 'DESC', $user_role = array(), $user_id = '', $limit = '', $offset = '', $where = '' ) {
118
- global $wpdb;
119
-
120
- // Set order direction
121
- $order_direction = 'DESC';
122
- if ( 'ASC' === $order ) {
123
- $order_direction = 'ASC';
124
- }
125
-
126
- // Set field to sort by
127
- switch ( $order_by ) {
128
- case 'last_activity':
129
- $order_field = 'last_activity';
130
- break;
131
-
132
- case 'quiz_views':
133
- $order_field = 'quiz_views';
134
- break;
135
-
136
- case 'quiz_taken':
137
- $order_field = 'quiz_taken';
138
- break;
139
-
140
- case 'title':
141
- $order_field = 'quiz_name';
142
- break;
143
-
144
- default:
145
- $order_field = 'quiz_id';
146
- break;
147
- }
148
-
149
- // Should we include deleted?
150
- $delete = "WHERE deleted=0";
151
- if ( '' !== $where ) {
152
- $delete = $delete . ' AND ' . $where;
153
- }
154
- if ( $include_deleted ) {
155
- $delete = '';
156
- }
157
- $user_str = '';
158
- if ( in_array('author', (array) $user_role, true ) ) {
159
- if ( $user_id && '' === $delete ) {
160
- $user_str = "WHERE quiz_author_id = '$user_id'";
161
- } elseif ( $user_id && '' !== $delete ) {
162
- $user_str = " AND quiz_author_id = '$user_id'";
163
- }
164
- }
165
- if ( '' !== $where && '' !== $user_str ) {
166
- $user_str = $user_str . ' AND ' . $where;
167
- }
168
- $where_str = '';
169
- if ( '' === $user_str && '' === $delete && '' !== $where ) {
170
- $where_str = "WHERE $where";
171
- }
172
- if ( '' !== $limit ) {
173
- $limit = ' limit ' . $offset . ', ' . $limit;
174
- }
175
- // Get quizzes and return them
176
- $delete = apply_filters( 'quiz_query_delete_clause', $delete );
177
- $quizzes = $wpdb->get_results(stripslashes($wpdb->prepare("SELECT * FROM {$wpdb->prefix}mlw_quizzes %1s %2s %3s ORDER BY %4s %5s %6s", $delete, $user_str, $where_str, $order_field, $order_direction, $limit)));
178
- return $quizzes;
179
- }
180
-
181
- /**
182
- * Registers a quiz setting
183
- *
184
- * @since 5.0.0
185
- * @param array $field_array An array of the components for the settings field
186
- */
187
- public function register_quiz_setting( $field_array, $section = 'quiz_options' ) {
188
- global $mlwQuizMasterNext;
189
- $mlwQuizMasterNext->quiz_settings->register_setting($field_array, $section);
190
- }
191
-
192
- /**
193
- * Retrieves a setting value from a section based on name of section and setting
194
- *
195
- * @since 5.0.0
196
- * @param string $section The name of the section the setting is registered in
197
- * @param string $setting The name of the setting whose value we need to retrieve
198
- * @param mixed $default What we need to return if no setting exists with given $setting
199
- * @return $mixed Value set for $setting or $default if setting does not exist
200
- */
201
- public function get_section_setting( $section, $setting, $default = false ) {
202
- global $mlwQuizMasterNext;
203
- return apply_filters('qsm_section_setting_text', $mlwQuizMasterNext->quiz_settings->get_section_setting($section, $setting, $default));
204
- }
205
-
206
- /**
207
- * Retrieves setting value based on name of setting
208
- *
209
- * @since 4.0.0
210
- * @param string $setting The name of the setting whose value we need to retrieve
211
- * @param mixed $default What we need to return if no setting exists with given $setting
212
- * @return $mixed Value set for $setting or $default if setting does not exist
213
- */
214
- public function get_quiz_setting( $setting, $default = false ) {
215
- global $mlwQuizMasterNext;
216
- return $mlwQuizMasterNext->quiz_settings->get_setting($setting, $default);
217
- }
218
-
219
- /**
220
- * Updates a settings value, adding it if it didn't already exist
221
- *
222
- * @since 4.0.0
223
- * @param string $setting The name of the setting whose value we need to retrieve
224
- * @param mixed $value The value that needs to be stored for the setting
225
- * @return bool True if successful or false if fails
226
- */
227
- public function update_quiz_setting( $setting, $value ) {
228
- global $mlwQuizMasterNext;
229
- return $mlwQuizMasterNext->quiz_settings->update_setting($setting, $value);
230
- }
231
-
232
- /**
233
- * Outputs the section of input fields
234
- *
235
- * @since 5.0.0
236
- * @since 7.0 Added new parameter settings_fields for default setting
237
- * @param string $section The section that the settings were registered with
238
- */
239
- public function generate_settings_section( $section = 'quiz_options', $settings_fields = array() ) {
240
- global $mlwQuizMasterNext;
241
- if ( empty($settings_fields) ) {
242
- $settings_fields = $mlwQuizMasterNext->quiz_settings->load_setting_fields($section);
243
- }
244
- QSM_Fields::generate_section($settings_fields, $section);
245
- }
246
-
247
- /**
248
- * Registers Quiz Templates
249
- *
250
- * @since 4.5.0
251
- * @param $name String of the name of the template
252
- * @param $file_path String of the path to the css file
253
- */
254
- public function register_quiz_template( $name, $file_path ) {
255
- $slug = strtolower(str_replace(" ", "-", $name));
256
- $this->quiz_templates[ $slug ] = array(
257
- "name" => $name,
258
- "path" => $file_path,
259
- );
260
- }
261
-
262
- /**
263
- * Returns Template Array
264
- *
265
- * @since 4.5.0
266
- * @param $name String of the name of the template. If left empty, will return all templates
267
- * @return array The array of quiz templates
268
- */
269
- public function get_quiz_templates( $slug = null ) {
270
- if ( is_null($slug) ) {
271
- return $this->quiz_templates;
272
- } elseif ( isset($this->quiz_templates[ $slug ]) ) {
273
- return $this->quiz_templates[ $slug ];
274
- } else {
275
- return false;
276
- }
277
- }
278
-
279
- /**
280
- * Register Question Types
281
- *
282
- * Adds a question type to the question type array using the parameters given
283
- *
284
- * @since 4.0.0
285
- * @param string $name The name of the Question Type which will be shown when selecting type
286
- * @param string $display_function The name of the function to call when displaying the question
287
- * @param bool $graded Tells the plugin if this question is graded or not. This will affect scoring.
288
- * @param string $review_function The name of the function to call when scoring the question
289
- * @param string $slug The slug of the question type to be stored with question in database
290
- * @return void
291
- */
292
- public function register_question_type( $name, $display_function, $graded, $review_function = null, $edit_args = null, $save_edit_function = null, $slug = null ) {
293
- if ( is_null($slug) ) {
294
- $slug = strtolower(str_replace(" ", "-", $name));
295
- } else {
296
- $slug = strtolower(str_replace(" ", "-", $slug));
297
- }
298
- if ( is_null($edit_args) || ! is_array($edit_args) ) {
299
- $validated_edit_function = array(
300
- 'inputs' => array(
301
- 'question',
302
- 'answer',
303
- 'hint',
304
- 'correct_info',
305
- 'comments',
306
- 'category',
307
- 'required',
308
- ),
309
- 'information' => '',
310
- 'extra_inputs' => array(),
311
- 'function' => '',
312
- );
313
- } else {
314
- $validated_edit_function = array(
315
- 'inputs' => $edit_args['inputs'],
316
- 'information' => $edit_args['information'],
317
- 'extra_inputs' => $edit_args['extra_inputs'],
318
- 'function' => $edit_args['function'],
319
- );
320
- }
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,
328
- 'graded' => $graded,
329
- 'edit' => $validated_edit_function,
330
- 'save' => $save_edit_function,
331
- 'slug' => $slug,
332
- );
333
- $this->question_types[] = $new_type;
334
- }
335
-
336
- /**
337
- * Retrieves List Of Question Types
338
- *
339
- * retrieves a list of the slugs and names of the question types
340
- *
341
- * @since 4.0.0
342
- * @return array An array which contains the slug and name of question types that have been registered
343
- */
344
- public function get_question_type_options() {
345
- $type_array = array();
346
- foreach ( $this->question_types as $type ) {
347
- $type_array[] = array(
348
- 'slug' => $type["slug"],
349
- 'name' => $type["name"],
350
- );
351
- }
352
- return $type_array;
353
- }
354
-
355
- public function get_question_type_edit_fields() {
356
- $type_array = array();
357
- foreach ( $this->question_types as $type ) {
358
- $type_array[ $type["slug"] ] = $type["edit"];
359
- }
360
- return $type_array;
361
- }
362
-
363
- /**
364
- * Displays A Question
365
- *
366
- * Retrieves the question types display function and creates the HTML for the question
367
- *
368
- * @since 4.0.0
369
- * @param string $slug The slug of the question type that the question is
370
- * @param int $question_id The id of the question
371
- * @param array $quiz_options An array of the columns of the quiz row from the database
372
- * @return string The HTML for the question
373
- */
374
- public function display_question( $slug, $question_id, $quiz_options ) {
375
- global $wpdb;
376
- global $qmn_total_questions;
377
- $question = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "mlw_questions WHERE question_id=%d", intval($question_id)));
378
- $answers = array();
379
- if ( is_serialized($question->answer_array) && is_array(maybe_unserialize($question->answer_array)) ) {
380
- $answers = maybe_unserialize($question->answer_array);
381
- } else {
382
- $mlw_answer_array_correct = array( 0, 0, 0, 0, 0, 0 );
383
- $mlw_answer_array_correct[ $question->correct_answer - 1 ] = 1;
384
- $answers = array(
385
- array( $question->answer_one, $question->answer_one_points, $mlw_answer_array_correct[0] ),
386
- array( $question->answer_two, $question->answer_two_points, $mlw_answer_array_correct[1] ),
387
- array( $question->answer_three, $question->answer_three_points, $mlw_answer_array_correct[2] ),
388
- array( $question->answer_four, $question->answer_four_points, $mlw_answer_array_correct[3] ),
389
- array( $question->answer_five, $question->answer_five_points, $mlw_answer_array_correct[4] ),
390
- array( $question->answer_six, $question->answer_six_points, $mlw_answer_array_correct[5] ),
391
  );
392
- }
393
- if ( 2 === intval( $quiz_options->randomness_order ) || 3 === intval ( $quiz_options->randomness_order ) ) {
394
- shuffle($answers);
395
- update_post_meta($question_id,'qsm_random_quetion_answer',$answers);
396
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  /**
398
  * Filter Answers of specific question before display
399
  */
400
- $answers = apply_filters('qsm_single_question_answers', $answers, $question, $quiz_options);
401
-
402
- foreach ( $this->question_types as $type ) {
403
- if ( strtolower(str_replace(" ", "-", $slug)) === $type["slug"] ) {
404
- if ( $type["graded"] ) {
405
- $qmn_total_questions += 1;
406
- if ( 1 === intval ( $quiz_options->question_numbering ) ) { ?>
407
- <span class='mlw_qmn_question_number'><?php echo esc_html( $qmn_total_questions ); ?></span>
408
- <?php
409
- }
410
- }
411
- if ( $quiz_options->show_category_on_front ) {
412
- $categories = QSM_Questions::get_question_categories( $question_id );
413
- if ( ! empty($categories['category_name']) ) {
414
- $cat_name = implode( ',' ,$categories['category_name'] );
415
- ?><div class="quiz-cat">[<?php echo esc_html( $cat_name ); ?>]</div><?php
416
- }
417
- }
418
- call_user_func($type['display'], intval($question_id), $question->question_name, $answers);
419
- }
420
- }
421
- }
422
-
423
- /**
424
- * Calculates Score For Question
425
- *
426
- * Calculates the score for the question based on the question type
427
- *
428
- * @since 4.0.0
429
- * @param string $slug The slug of the question type that the question is
430
- * @param int $question_id The id of the question
431
- * @return array An array of the user's score from the question
432
- */
433
- public function display_review( $slug, $question_id ) {
434
- $results_array = array();
435
- global $wpdb;
436
- $question = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "mlw_questions WHERE question_id=%d", intval($question_id)));
437
- $answers = maybe_unserialize( $question->answer_array );
438
- if ( empty( $answers ) || ! is_array( $answers ) ) {
439
- $mlw_answer_array_correct = array( 0, 0, 0, 0, 0, 0 );
440
- $mlw_answer_array_correct[ $question->correct_answer - 1 ] = 1;
441
- $answers = array(
442
- array( $question->answer_one, $question->answer_one_points, $mlw_answer_array_correct[0] ),
443
- array( $question->answer_two, $question->answer_two_points, $mlw_answer_array_correct[1] ),
444
- array( $question->answer_three, $question->answer_three_points, $mlw_answer_array_correct[2] ),
445
- array( $question->answer_four, $question->answer_four_points, $mlw_answer_array_correct[3] ),
446
- array( $question->answer_five, $question->answer_five_points, $mlw_answer_array_correct[4] ),
447
- array( $question->answer_six, $question->answer_six_points, $mlw_answer_array_correct[5] ),
 
 
448
  );
449
- }
450
- foreach ( $this->question_types as $type ) {
451
- if ( strtolower(str_replace(" ", "-", $slug)) === $type["slug"] ) {
452
- if ( ! is_null($type["review"]) ) {
453
- $results_array = call_user_func($type['review'], intval($question_id), $question->question_name, $answers);
454
- } else {
455
- $results_array = array( 'null_review' => true );
456
- }
457
- }
458
- }
459
- return $results_array;
460
- }
461
-
462
- /**
463
- * Retrieves A Question Setting
464
- *
465
- * Retrieves a setting stored in the question settings array
466
- *
467
- * @since 4.0.0
468
- * @param int $question_id The id of the question
469
- * @param string $setting The name of the setting
470
- * @return string The value stored for the setting
471
- */
472
- public function get_question_setting( $question_id, $setting ) {
473
- global $wpdb;
474
- $settings = $wpdb->get_var($wpdb->prepare("SELECT question_settings FROM " . $wpdb->prefix . "mlw_questions WHERE question_id=%d", $question_id));
475
- $qmn_settings_array = maybe_unserialize( $settings );
476
-
477
- if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting ] ) ) {
478
- return $qmn_settings_array[ $setting ];
479
- } else {
480
- return '';
481
- }
482
- }
483
-
484
- /**
485
- * Registers Addon Settings Tab
486
- *
487
- * Registers a new tab on the addon settings page
488
- *
489
- * @since 4.0.0
490
- * @param string $title The name of the tab
491
- * @param string $function The function that displays the tab's content
492
- * @return void
493
- */
494
- public function register_addon_settings_tab( $title, $function ) {
495
- $slug = strtolower(str_replace(" ", "-", $title));
496
- $new_tab = array(
497
- 'title' => $title,
498
- 'function' => $function,
499
- 'slug' => $slug,
500
- );
501
- $this->addon_tabs[] = $new_tab;
502
- }
503
-
504
- /**
505
- * Retrieves Addon Settings Tab Array
506
- *
507
- * Retrieves the array of titles and functions of the registered tabs
508
- *
509
- * @since 4.0.0
510
- * @return array The array of registered tabs
511
- */
512
- public function get_addon_tabs() {
513
- return $this->addon_tabs;
514
- }
515
-
516
- /**
517
- * Registers Stats Tab
518
- *
519
- * Registers a new tab on the stats page
520
- *
521
- * @since 4.3.0
522
- * @param string $title The name of the tab
523
- * @param string $function The function that displays the tab's content
524
- * @return void
525
- */
526
- public function register_stats_settings_tab( $title, $function ) {
527
- $slug = strtolower(str_replace(" ", "-", $title));
528
- $new_tab = array(
529
- 'title' => $title,
530
- 'function' => $function,
531
- 'slug' => $slug,
532
- );
533
- $this->stats_tabs[] = $new_tab;
534
- }
535
-
536
- /**
537
- * Retrieves Stats Tab Array
538
- *
539
- * Retrieves the array of titles and functions of the registered tabs
540
- *
541
- * @since 4.3.0
542
- * @return array The array of registered tabs
543
- */
544
- public function get_stats_tabs() {
545
- return $this->stats_tabs;
546
- }
547
-
548
- /**
549
- * Registers tabs for the Admin Results page
550
- *
551
- * Registers a new tab on the admin results page
552
- *
553
- * @since 5.0.0
554
- * @param string $title The name of the tab
555
- * @param string $function The function that displays the tab's content
556
- * @return void
557
- */
558
- public function register_admin_results_tab( $title, $function ) {
559
- $slug = strtolower(str_replace(" ", "-", $title));
560
- $new_tab = array(
561
- 'title' => $title,
562
- 'function' => $function,
563
- 'slug' => $slug,
564
- );
565
- $this->admin_results_tabs[] = $new_tab;
566
- }
567
-
568
- /**
569
- * Retrieves Admin Results Tab Array
570
- *
571
- * Retrieves the array of titles and functions for the tabs registered for the admin results page
572
- *
573
- * @since 5.0.0
574
- * @return array The array of registered tabs
575
- */
576
- public function get_admin_results_tabs() {
577
- return $this->admin_results_tabs;
578
- }
579
-
580
- /**
581
- * Registers Results Tab
582
- *
583
- * Registers a new tab on the results page
584
- *
585
- * @since 4.1.0
586
- * @param string $title The name of the tab
587
- * @param string $function The function that displays the tab's content
588
- * @return void
589
- */
590
- public function register_results_settings_tab( $title, $function ) {
591
- $slug = strtolower(str_replace(" ", "-", $title));
592
- $new_tab = array(
593
- 'title' => $title,
594
- 'function' => $function,
595
- 'slug' => $slug,
596
- );
597
- $this->results_tabs[] = $new_tab;
598
- }
599
-
600
- /**
601
- * Retrieves Results Tab Array
602
- *
603
- * Retrieves the array of titles and functions of the registered tabs
604
- *
605
- * @since 4.1.0
606
- * @return array The array of registered tabs
607
- */
608
- public function get_results_tabs() {
609
- return $this->results_tabs;
610
- }
611
-
612
- /**
613
- * Registers Quiz Settings Tab
614
- *
615
- * Registers a new tab on the quiz settings page
616
- *
617
- * @since 4.0.0
618
- * @param string $title The name of the tab
619
- * @param string $function The function that displays the tab's content
620
- * @return void
621
- */
622
- public function register_quiz_settings_tabs( $title, $function ) {
623
- $slug = strtolower(str_replace(" ", "-", $title));
624
- $new_tab = array(
625
- 'title' => $title,
626
- 'function' => $function,
627
- 'slug' => $slug,
628
- );
629
- $this->settings_tabs[] = $new_tab;
630
- }
631
-
632
- /**
633
- * Echos Registered Tabs Title Link
634
- *
635
- * Echos the title link of the registered tabs
636
- *
637
- * @since 4.0.0
638
- * @return array The array of registered tabs
639
- */
640
- public function get_settings_tabs() {
641
- return apply_filters('qmn_quiz_setting_tabs' , $this->settings_tabs);
642
- }
643
-
644
- /**
645
- * global animatiocv array return
646
- *
647
- * @since 4.7.1
648
- */
649
- public function quiz_animation_effect( ) {
650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
 
652
  return array(
653
  array(
@@ -698,137 +704,136 @@ class QMNPluginHelper
698
 
699
  }
700
 
701
- /**
702
  * converts dates into preferred date format
703
  *
704
- * @since 7.3.3
705
- * @param array $qsm_qna_array The array of results for the quiz
706
- * @uses QMNQuizManager:submit_results() submits and displays results
707
- * @uses qsm_generate_results_details_tab() generates admin results page
708
  * @return array $qsm_qna_array date formatted array of results for the quiz
709
  */
710
 
711
  public function convert_to_preferred_date_format( $qsm_qna_array ) {
712
- global $mlwQuizMasterNext;
713
- $quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
714
- $qsm_quiz_settings = maybe_unserialize($quiz_options->quiz_settings);
715
- $qsm_quiz_options = maybe_unserialize($qsm_quiz_settings['quiz_options']);
716
- $qsm_global_settings = get_option( 'qsm-quiz-settings' );
717
- //check if preferred date format is set at quiz level or plugin level. Default to WP date format otherwise
718
- if ( isset($qsm_quiz_options['preferred_date_format']) ) {
719
- $preferred_date_format = $qsm_quiz_options['preferred_date_format'];
720
- } elseif ( isset($qsm_global_settings['preferred_date_format']) ) {
721
- $preferred_date_format = isset($qsm_global_settings['preferred_date_format']);
722
- }else {
723
- $preferred_date_format = get_option( 'date_format');
724
- }
725
- //filter date format
726
- $GLOBALS['qsm_date_format'] = apply_filters('qms_preferred_date_format', $preferred_date_format);
727
-
728
- $qsm_qna_array = $this->convert_contacts_to_preferred_date_format($qsm_qna_array);
729
- $qsm_qna_array = $this->convert_answers_to_preferred_date_format($qsm_qna_array);
730
- $this->convert_questions_to_preferred_date_format();
731
-
732
- return $qsm_qna_array;
733
- }
734
-
735
- /**
736
  * converts contacts into preferred date format
737
  *
738
- * @since 7.3.3
739
- * @param array $qsm_qna_array The array of results for the quiz
740
- * @uses convert_to_preferred_date_format()
741
  * @return array $qsm_qna_array date formatted array of results for the quiz
742
  */
743
 
744
  public function convert_contacts_to_preferred_date_format( $qsm_qna_array ) {
745
 
746
- $qsm_contact_array = $qsm_qna_array['contact'];
747
- foreach ( $qsm_contact_array as $qsm_contact_id => $qsm_contact ) {
748
- if ( "date" === $qsm_contact['type'] && null !== $GLOBALS['qsm_date_format'] ) {
749
- $qsm_qna_array['contact'][ $qsm_contact_id ]['value'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime(($qsm_contact['value'])));
750
- }
751
- }
752
- return $qsm_qna_array;
753
  }
754
 
755
- /**
756
  * converts answers into preferred date format
757
  *
758
- * @since 7.3.3
759
- * @param array $qsm_qna_array The array of results for the quiz
760
- * @uses convert_to_preferred_date_format()
761
  * @return array $qsm_qna_array date formatted array of results for the quiz
762
  */
763
 
764
  public function convert_answers_to_preferred_date_format( $qsm_qna_array ) {
765
 
766
- $qsm_qna_list = $qsm_qna_array['question_answers_array'];
767
- foreach ( $qsm_qna_list as $qna_id => $qna ) {
768
- if ( "12" === $qna['question_type'] && null !== $GLOBALS['qsm_date_format'] ) {
769
- $qsm_qna_array['question_answers_array'][ $qna_id ]['1'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime(($qna['1'])));
770
- $qsm_qna_array['question_answers_array'][ $qna_id ]['2'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime(($qna['2'])));
771
- }
772
- }
773
- return $qsm_qna_array;
774
  }
775
 
776
- /**
777
  * converts questions into preferred date format
778
  *
779
- * @since 7.3.3
780
- * @param array $qsm_qna_array The array of results for the quiz
781
- * @uses convert_to_preferred_date_format()
782
  * @return array $qsm_qna_array date formatted array of results for the quiz
783
  */
784
 
785
- public function convert_questions_to_preferred_date_format(){
786
-
787
- if ( ! function_exists('qsm_convert_question_array_date_format') ) {
788
- function qsm_convert_question_array_date_format( $questions ) {
789
- foreach ( $questions as $question_id => $question_to_convert ) {
790
- if ( "12" === $question_to_convert['question_type_new'] ) {
791
- foreach ( $question_to_convert['answers'] as $answer_id => $answer_value ) {
792
- $questions[ $question_id ]['answers'][ $answer_id ][0] = date_i18n( $GLOBALS['qsm_date_format'], strtotime($answer_value[0]));
793
- }
794
- }
795
- }
796
- return $questions;
797
- }
798
- }
799
- add_filter( 'qsm_load_questions_by_pages','qsm_convert_question_array_date_format');
800
  }
801
 
802
- /**
803
  *
804
  *
805
- * @since 7.3.5
806
- * @param array
807
  * @uses
808
  * @return array
809
  */
810
 
811
- public function qsm_results_css_inliner( $html ) {
812
-
813
- $incorrect_answer = "<span style='color:red;display:block;margin-bottom:5px;'>&#x2715;";
814
- $correct_answer = "<span style='color:green;display:block;margin-bottom:5px;'>&#10003;";
815
- $simple_answer = "<span style='color:#808080;display:block;margin-bottom:5px;'>&#8226;&nbsp;";
816
- $html = str_replace( '<br/>', '<br>', $html );
817
- $html = str_replace( '<br />', '<br>', $html );
818
- $html = str_replace( "<span class='qmn_user_incorrect_answer'>", "<span style='color:red'>&#x2715; ", $html );
819
- $html = str_replace( "<span class='qmn_user_correct_answer'>", "<span style='color:green'>&#10003; ", $html );
820
- $html = str_replace( '<span class="qsm-text-wrong-option qmn_image_option">', "$incorrect_answer ", $html );
821
- $html = str_replace( '<span class="qsm-text-correct-option qmn_image_option">', "$correct_answer ", $html );
822
- $html = str_replace( '<span class="qsm-text-correct-option qsm-text-user-correct-answer qmn_image_option">', "$correct_answer ", $html );
823
- $html = str_replace( '<span class="qsm-text-simple-option qmn_image_option">', "$simple_answer ", $html );
824
- $html = str_replace( '<span class="qsm-text-correct-option qsm-text-user-correct-answer ">', "$correct_answer ", $html );
825
- $html = str_replace( '<span class="qsm-text-simple-option ">', "$simple_answer ", $html );
826
- $html = str_replace( '<span class="qsm-text-wrong-option ">', "$incorrect_answer ", $html );
827
- $html = str_replace( '<span class="qsm-text-correct-option ">', "$correct_answer ", $html );
828
- $html = str_replace( '<span class="qmn_user_incorrect_answer">', "$incorrect_answer ", $html );
829
- $html = str_replace( '<span class="qmn_user_incorrect_answer">', "$correct_answer ", $html );
830
- $html = str_replace( "class='qmn_question_answer", "style='margin-bottom:30px' class='", $html );
831
-
832
- return $html;
833
- }
834
  }
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
  }
5
 
6
  /**
10
  *
11
  * @since 4.0.0
12
  */
13
+ class QMNPluginHelper {
14
+
15
+
16
+ /**
17
+ * Addon Page tabs array
18
+ *
19
+ * @var array
20
+ * @since 4.0.0
21
+ */
22
+ public $addon_tabs = array();
23
+
24
+ /**
25
+ * Stats Page tabs array
26
+ *
27
+ * @var array
28
+ * @since 4.0.0
29
+ */
30
+ public $stats_tabs = array();
31
+
32
+ /**
33
+ * Admin Results Page tabs array
34
+ *
35
+ * @var array
36
+ * @since 5.0.0
37
+ */
38
+ public $admin_results_tabs = array();
39
+
40
+ /**
41
+ * Results Details Page tabs array
42
+ *
43
+ * @var array
44
+ * @since 4.1.0
45
+ */
46
+ public $results_tabs = array();
47
+
48
+ /**
49
+ * Settings Page tabs array
50
+ *
51
+ * @var array
52
+ * @since 4.0.0
53
+ */
54
+ public $settings_tabs = array();
55
+
56
+ /**
57
+ * Question types array
58
+ *
59
+ * @var array
60
+ * @since 4.0.0
61
+ */
62
+ public $question_types = array();
63
+
64
+ /**
65
+ * Template array
66
+ *
67
+ * @var array
68
+ * @since 4.5.0
69
+ */
70
+ public $quiz_templates = array();
71
+
72
+ /**
73
+ * Main Construct Function
74
+ *
75
+ * Call functions within class
76
+ *
77
+ * @since 4.0.0
78
+ * @return void
79
+ */
80
+ public function __construct() {
81
+ add_action( 'wp_ajax_qmn_question_type_change', array( $this, 'get_question_type_edit_content' ) );
82
+ }
83
+
84
+ /**
85
+ * Calls all class functions to initialize quiz
86
+ *
87
+ * @param int $quiz_id The ID of the quiz or survey to load.
88
+ * @return bool True or False if ID is valid.
89
+ */
90
+ public function prepare_quiz( $quiz_id ) {
91
+ $quiz_id = intval( $quiz_id );
92
+
93
+ // Tries to load quiz name to ensure this is a valid ID.
94
+ global $wpdb;
95
+ $quiz_name = $wpdb->get_var( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $quiz_id ) );
96
+ if ( is_null( $quiz_name ) ) {
97
+ return false;
98
+ }
99
+
100
+ global $mlwQuizMasterNext;
101
+ $mlwQuizMasterNext->quizCreator->set_id( $quiz_id );
102
+ $mlwQuizMasterNext->quiz_settings->prepare_quiz( $quiz_id );
103
+
104
+ return true;
105
+ }
106
+
107
+ /**
108
+ * Retrieves all quizzes.
109
+ *
110
+ * @param bool $include_deleted If set to true, returned array will include all deleted quizzes
111
+ * @param string $order_by The column the quizzes should be ordered by
112
+ * @param string $order whether the $order_by should be ordered as ascending or decending. Can be "ASC" or "DESC"
113
+ * @param arr $user_role role of current user
114
+ * @param int $user_id Get the quiz based on user id
115
+ * @return array All of the quizzes as a numerical array of objects
116
+ */
117
+ public function get_quizzes( $include_deleted = false, $order_by = 'quiz_id', $order = 'DESC', $user_role = array(), $user_id = '', $limit = '', $offset = '', $where = '' ) {
118
+ global $wpdb;
119
+
120
+ // Set order direction
121
+ $order_direction = 'DESC';
122
+ if ( 'ASC' === $order ) {
123
+ $order_direction = 'ASC';
124
+ }
125
+
126
+ // Set field to sort by
127
+ switch ( $order_by ) {
128
+ case 'last_activity':
129
+ $order_field = 'last_activity';
130
+ break;
131
+
132
+ case 'quiz_views':
133
+ $order_field = 'quiz_views';
134
+ break;
135
+
136
+ case 'quiz_taken':
137
+ $order_field = 'quiz_taken';
138
+ break;
139
+
140
+ case 'title':
141
+ $order_field = 'quiz_name';
142
+ break;
143
+
144
+ default:
145
+ $order_field = 'quiz_id';
146
+ break;
147
+ }
148
+
149
+ // Should we include deleted?
150
+ $delete = 'WHERE deleted=0';
151
+ if ( '' !== $where ) {
152
+ $delete = $delete . ' AND ' . $where;
153
+ }
154
+ if ( $include_deleted ) {
155
+ $delete = '';
156
+ }
157
+ $user_str = '';
158
+ if ( in_array( 'author', (array) $user_role, true ) ) {
159
+ if ( $user_id && '' === $delete ) {
160
+ $user_str = "WHERE quiz_author_id = '$user_id'";
161
+ } elseif ( $user_id && '' !== $delete ) {
162
+ $user_str = " AND quiz_author_id = '$user_id'";
163
+ }
164
+ }
165
+ if ( '' !== $where && '' !== $user_str ) {
166
+ $user_str = $user_str . ' AND ' . $where;
167
+ }
168
+ $where_str = '';
169
+ if ( '' === $user_str && '' === $delete && '' !== $where ) {
170
+ $where_str = "WHERE $where";
171
+ }
172
+ if ( '' !== $limit ) {
173
+ $limit = ' limit ' . $offset . ', ' . $limit;
174
+ }
175
+ // Get quizzes and return them
176
+ $delete = apply_filters( 'quiz_query_delete_clause', $delete );
177
+ $quizzes = $wpdb->get_results( stripslashes( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_quizzes %1s %2s %3s ORDER BY %4s %5s %6s", $delete, $user_str, $where_str, $order_field, $order_direction, $limit ) ) );
178
+ return $quizzes;
179
+ }
180
+
181
+ /**
182
+ * Registers a quiz setting
183
+ *
184
+ * @since 5.0.0
185
+ * @param array $field_array An array of the components for the settings field
186
+ */
187
+ public function register_quiz_setting( $field_array, $section = 'quiz_options' ) {
188
+ global $mlwQuizMasterNext;
189
+ $mlwQuizMasterNext->quiz_settings->register_setting( $field_array, $section );
190
+ }
191
+
192
+ /**
193
+ * Retrieves a setting value from a section based on name of section and setting
194
+ *
195
+ * @since 5.0.0
196
+ * @param string $section The name of the section the setting is registered in
197
+ * @param string $setting The name of the setting whose value we need to retrieve
198
+ * @param mixed $default What we need to return if no setting exists with given $setting
199
+ * @return $mixed Value set for $setting or $default if setting does not exist
200
+ */
201
+ public function get_section_setting( $section, $setting, $default = false ) {
202
+ global $mlwQuizMasterNext;
203
+ return apply_filters( 'qsm_section_setting_text', $mlwQuizMasterNext->quiz_settings->get_section_setting( $section, $setting, $default ) );
204
+ }
205
+
206
+ /**
207
+ * Retrieves setting value based on name of setting
208
+ *
209
+ * @since 4.0.0
210
+ * @param string $setting The name of the setting whose value we need to retrieve
211
+ * @param mixed $default What we need to return if no setting exists with given $setting
212
+ * @return $mixed Value set for $setting or $default if setting does not exist
213
+ */
214
+ public function get_quiz_setting( $setting, $default = false ) {
215
+ global $mlwQuizMasterNext;
216
+ return $mlwQuizMasterNext->quiz_settings->get_setting( $setting, $default );
217
+ }
218
+
219
+ /**
220
+ * Updates a settings value, adding it if it didn't already exist
221
+ *
222
+ * @since 4.0.0
223
+ * @param string $setting The name of the setting whose value we need to retrieve
224
+ * @param mixed $value The value that needs to be stored for the setting
225
+ * @return bool True if successful or false if fails
226
+ */
227
+ public function update_quiz_setting( $setting, $value ) {
228
+ global $mlwQuizMasterNext;
229
+ return $mlwQuizMasterNext->quiz_settings->update_setting( $setting, $value );
230
+ }
231
+
232
+ /**
233
+ * Outputs the section of input fields
234
+ *
235
+ * @since 5.0.0
236
+ * @since 7.0 Added new parameter settings_fields for default setting
237
+ * @param string $section The section that the settings were registered with
238
+ */
239
+ public function generate_settings_section( $section = 'quiz_options', $settings_fields = array() ) {
240
+ global $mlwQuizMasterNext;
241
+ if ( empty( $settings_fields ) ) {
242
+ $settings_fields = $mlwQuizMasterNext->quiz_settings->load_setting_fields( $section );
243
+ }
244
+ QSM_Fields::generate_section( $settings_fields, $section );
245
+ }
246
+
247
+ /**
248
+ * Registers Quiz Templates
249
+ *
250
+ * @since 4.5.0
251
+ * @param $name String of the name of the template
252
+ * @param $file_path String of the path to the css file
253
+ */
254
+ public function register_quiz_template( $name, $file_path ) {
255
+ $slug = strtolower( str_replace( ' ', '-', $name ) );
256
+ $this->quiz_templates[ $slug ] = array(
257
+ 'name' => $name,
258
+ 'path' => $file_path,
259
+ );
260
+ }
261
+
262
+ /**
263
+ * Returns Template Array
264
+ *
265
+ * @since 4.5.0
266
+ * @param $name String of the name of the template. If left empty, will return all templates
267
+ * @return array The array of quiz templates
268
+ */
269
+ public function get_quiz_templates( $slug = null ) {
270
+ if ( is_null( $slug ) ) {
271
+ return $this->quiz_templates;
272
+ } elseif ( isset( $this->quiz_templates[ $slug ] ) ) {
273
+ return $this->quiz_templates[ $slug ];
274
+ } else {
275
+ return false;
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Register Question Types
281
+ *
282
+ * Adds a question type to the question type array using the parameters given
283
+ *
284
+ * @since 4.0.0
285
+ * @param string $name The name of the Question Type which will be shown when selecting type
286
+ * @param string $display_function The name of the function to call when displaying the question
287
+ * @param bool $graded Tells the plugin if this question is graded or not. This will affect scoring.
288
+ * @param string $review_function The name of the function to call when scoring the question
289
+ * @param string $slug The slug of the question type to be stored with question in database
290
+ * @param array $options The options for show and hide question validation settings and answer types
291
+ * @return void
292
+ */
293
+ public function register_question_type( $name, $display_function, $graded, $review_function = null, $edit_args = null, $save_edit_function = null, $slug = null, $options = array() ) {
294
+ if ( is_null( $slug ) ) {
295
+ $slug = strtolower( str_replace( ' ', '-', $name ) );
296
+ } else {
297
+ $slug = strtolower( str_replace( ' ', '-', $slug ) );
298
+ }
299
+ if ( is_null( $edit_args ) || ! is_array( $edit_args ) ) {
300
+ $validated_edit_function = array(
301
+ 'inputs' => array(
302
+ 'question',
303
+ 'answer',
304
+ 'hint',
305
+ 'correct_info',
306
+ 'comments',
307
+ 'category',
308
+ 'required',
309
+ ),
310
+ 'information' => '',
311
+ 'extra_inputs' => array(),
312
+ 'function' => '',
313
+ );
314
+ } else {
315
+ $validated_edit_function = array(
316
+ 'inputs' => $edit_args['inputs'],
317
+ 'information' => $edit_args['information'],
318
+ 'extra_inputs' => $edit_args['extra_inputs'],
319
+ 'function' => $edit_args['function'],
320
+ );
321
+ }
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,
329
+ 'graded' => $graded,
330
+ 'edit' => $validated_edit_function,
331
+ 'save' => $save_edit_function,
332
+ 'slug' => $slug,
333
+ 'options' => $options,
334
+ );
335
+ $this->question_types[] = $new_type;
336
+ }
337
+
338
+ /**
339
+ * Retrieves List Of Question Types
340
+ *
341
+ * retrieves a list of the slugs and names of the question types
342
+ *
343
+ * @since 4.0.0
344
+ * @return array An array which contains the slug and name of question types that have been registered
345
+ */
346
+ public function get_question_type_options() {
347
+ $type_array = array();
348
+ foreach ( $this->question_types as $type ) {
349
+ $type_array[] = array(
350
+ 'slug' => $type['slug'],
351
+ 'name' => $type['name'],
352
+ 'options' => $type['options'],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  );
354
+ }
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 ) {
361
+ $type_array[ $type['slug'] ] = $type['edit'];
362
+ }
363
+ return $type_array;
364
+ }
365
+
366
+ /**
367
+ * Displays A Question
368
+ *
369
+ * Retrieves the question types display function and creates the HTML for the question
370
+ *
371
+ * @since 4.0.0
372
+ * @param string $slug The slug of the question type that the question is
373
+ * @param int $question_id The id of the question
374
+ * @param array $quiz_options An array of the columns of the quiz row from the database
375
+ * @return string The HTML for the question
376
+ */
377
+ public function display_question( $slug, $question_id, $quiz_options ) {
378
+ global $wpdb;
379
+ global $qmn_total_questions;
380
+ $question = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'mlw_questions WHERE question_id=%d', intval( $question_id ) ) );
381
+ $answers = array();
382
+ if ( is_serialized( $question->answer_array ) && is_array( maybe_unserialize( $question->answer_array ) ) ) {
383
+ $answers = maybe_unserialize( $question->answer_array );
384
+ } else {
385
+ $mlw_answer_array_correct = array( 0, 0, 0, 0, 0, 0 );
386
+ $mlw_answer_array_correct[ $question->correct_answer - 1 ] = 1;
387
+ $answers = array(
388
+ array( $question->answer_one, $question->answer_one_points, $mlw_answer_array_correct[0] ),
389
+ array( $question->answer_two, $question->answer_two_points, $mlw_answer_array_correct[1] ),
390
+ array( $question->answer_three, $question->answer_three_points, $mlw_answer_array_correct[2] ),
391
+ array( $question->answer_four, $question->answer_four_points, $mlw_answer_array_correct[3] ),
392
+ array( $question->answer_five, $question->answer_five_points, $mlw_answer_array_correct[4] ),
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
  */
403
+ $answers = apply_filters( 'qsm_single_question_answers', $answers, $question, $quiz_options );
404
+
405
+ foreach ( $this->question_types as $type ) {
406
+ if ( strtolower( str_replace( ' ', '-', $slug ) ) === $type['slug'] ) {
407
+ if ( $type['graded'] ) {
408
+ $qmn_total_questions += 1;
409
+ if ( 1 === intval( $quiz_options->question_numbering ) ) { ?>
410
+ <span class='mlw_qmn_question_number'><?php echo esc_html( $qmn_total_questions ); ?></span>
411
+ <?php
412
+ }
413
+ }
414
+ if ( $quiz_options->show_category_on_front ) {
415
+ $categories = QSM_Questions::get_question_categories( $question_id );
416
+ if ( ! empty( $categories['category_name'] ) ) {
417
+ $cat_name = implode( ',', $categories['category_name'] );
418
+ ?>
419
+ <div class="quiz-cat">[<?php echo esc_html( $cat_name ); ?>]</div>
420
+ <?php
421
+ }
422
+ }
423
+ call_user_func( $type['display'], intval( $question_id ), $question->question_name, $answers );
424
+ }
425
+ }
426
+ }
427
+
428
+ /**
429
+ * Calculates Score For Question
430
+ *
431
+ * Calculates the score for the question based on the question type
432
+ *
433
+ * @since 4.0.0
434
+ * @param string $slug The slug of the question type that the question is
435
+ * @param int $question_id The id of the question
436
+ * @return array An array of the user's score from the question
437
+ */
438
+ public function display_review( $slug, $question_id ) {
439
+ $results_array = array();
440
+ global $wpdb;
441
+ $question = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'mlw_questions WHERE question_id=%d', intval( $question_id ) ) );
442
+ $answers = maybe_unserialize( $question->answer_array );
443
+ if ( empty( $answers ) || ! is_array( $answers ) ) {
444
+ $mlw_answer_array_correct = array( 0, 0, 0, 0, 0, 0 );
445
+ $mlw_answer_array_correct[ $question->correct_answer - 1 ] = 1;
446
+ $answers = array(
447
+ array( $question->answer_one, $question->answer_one_points, $mlw_answer_array_correct[0] ),
448
+ array( $question->answer_two, $question->answer_two_points, $mlw_answer_array_correct[1] ),
449
+ array( $question->answer_three, $question->answer_three_points, $mlw_answer_array_correct[2] ),
450
+ array( $question->answer_four, $question->answer_four_points, $mlw_answer_array_correct[3] ),
451
+ array( $question->answer_five, $question->answer_five_points, $mlw_answer_array_correct[4] ),
452
+ array( $question->answer_six, $question->answer_six_points, $mlw_answer_array_correct[5] ),
453
  );
454
+ }
455
+ foreach ( $this->question_types as $type ) {
456
+ if ( strtolower( str_replace( ' ', '-', $slug ) ) === $type['slug'] ) {
457
+ if ( ! is_null( $type['review'] ) ) {
458
+ $results_array = call_user_func( $type['review'], intval( $question_id ), $question->question_name, $answers );
459
+ } else {
460
+ $results_array = array( 'null_review' => true );
461
+ }
462
+ }
463
+ }
464
+ return $results_array;
465
+ }
466
+
467
+ /**
468
+ * Retrieves A Question Setting
469
+ *
470
+ * Retrieves a setting stored in the question settings array
471
+ *
472
+ * @since 4.0.0
473
+ * @param int $question_id The id of the question
474
+ * @param string $setting The name of the setting
475
+ * @return string The value stored for the setting
476
+ */
477
+ public function get_question_setting( $question_id, $setting ) {
478
+ global $wpdb;
479
+ $settings = $wpdb->get_var( $wpdb->prepare( 'SELECT question_settings FROM ' . $wpdb->prefix . 'mlw_questions WHERE question_id=%d', $question_id ) );
480
+ $qmn_settings_array = maybe_unserialize( $settings );
481
+
482
+ if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting ] ) ) {
483
+ return $qmn_settings_array[ $setting ];
484
+ } else {
485
+ return '';
486
+ }
487
+ }
488
+
489
+ /**
490
+ * Registers Addon Settings Tab
491
+ *
492
+ * Registers a new tab on the addon settings page
493
+ *
494
+ * @since 4.0.0
495
+ * @param string $title The name of the tab
496
+ * @param string $function The function that displays the tab's content
497
+ * @return void
498
+ */
499
+ public function register_addon_settings_tab( $title, $function ) {
500
+ $slug = strtolower( str_replace( ' ', '-', $title ) );
501
+ $new_tab = array(
502
+ 'title' => $title,
503
+ 'function' => $function,
504
+ 'slug' => $slug,
505
+ );
506
+ $this->addon_tabs[] = $new_tab;
507
+ }
508
+
509
+ /**
510
+ * Retrieves Addon Settings Tab Array
511
+ *
512
+ * Retrieves the array of titles and functions of the registered tabs
513
+ *
514
+ * @since 4.0.0
515
+ * @return array The array of registered tabs
516
+ */
517
+ public function get_addon_tabs() {
518
+ return $this->addon_tabs;
519
+ }
520
+
521
+ /**
522
+ * Registers Stats Tab
523
+ *
524
+ * Registers a new tab on the stats page
525
+ *
526
+ * @since 4.3.0
527
+ * @param string $title The name of the tab
528
+ * @param string $function The function that displays the tab's content
529
+ * @return void
530
+ */
531
+ public function register_stats_settings_tab( $title, $function ) {
532
+ $slug = strtolower( str_replace( ' ', '-', $title ) );
533
+ $new_tab = array(
534
+ 'title' => $title,
535
+ 'function' => $function,
536
+ 'slug' => $slug,
537
+ );
538
+ $this->stats_tabs[] = $new_tab;
539
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
540
 
541
+ /**
542
+ * Retrieves Stats Tab Array
543
+ *
544
+ * Retrieves the array of titles and functions of the registered tabs
545
+ *
546
+ * @since 4.3.0
547
+ * @return array The array of registered tabs
548
+ */
549
+ public function get_stats_tabs() {
550
+ return $this->stats_tabs;
551
+ }
552
+
553
+ /**
554
+ * Registers tabs for the Admin Results page
555
+ *
556
+ * Registers a new tab on the admin results page
557
+ *
558
+ * @since 5.0.0
559
+ * @param string $title The name of the tab
560
+ * @param string $function The function that displays the tab's content
561
+ * @return void
562
+ */
563
+ public function register_admin_results_tab( $title, $function ) {
564
+ $slug = strtolower( str_replace( ' ', '-', $title ) );
565
+ $new_tab = array(
566
+ 'title' => $title,
567
+ 'function' => $function,
568
+ 'slug' => $slug,
569
+ );
570
+ $this->admin_results_tabs[] = $new_tab;
571
+ }
572
+
573
+ /**
574
+ * Retrieves Admin Results Tab Array
575
+ *
576
+ * Retrieves the array of titles and functions for the tabs registered for the admin results page
577
+ *
578
+ * @since 5.0.0
579
+ * @return array The array of registered tabs
580
+ */
581
+ public function get_admin_results_tabs() {
582
+ return $this->admin_results_tabs;
583
+ }
584
+
585
+ /**
586
+ * Registers Results Tab
587
+ *
588
+ * Registers a new tab on the results page
589
+ *
590
+ * @since 4.1.0
591
+ * @param string $title The name of the tab
592
+ * @param string $function The function that displays the tab's content
593
+ * @return void
594
+ */
595
+ public function register_results_settings_tab( $title, $function ) {
596
+ $slug = strtolower( str_replace( ' ', '-', $title ) );
597
+ $new_tab = array(
598
+ 'title' => $title,
599
+ 'function' => $function,
600
+ 'slug' => $slug,
601
+ );
602
+ $this->results_tabs[] = $new_tab;
603
+ }
604
+
605
+ /**
606
+ * Retrieves Results Tab Array
607
+ *
608
+ * Retrieves the array of titles and functions of the registered tabs
609
+ *
610
+ * @since 4.1.0
611
+ * @return array The array of registered tabs
612
+ */
613
+ public function get_results_tabs() {
614
+ return $this->results_tabs;
615
+ }
616
+
617
+ /**
618
+ * Registers Quiz Settings Tab
619
+ *
620
+ * Registers a new tab on the quiz settings page
621
+ *
622
+ * @since 4.0.0
623
+ * @param string $title The name of the tab
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,
635
+ );
636
+ $this->settings_tabs[] = $new_tab;
637
+ }
638
+
639
+ /**
640
+ * Echos Registered Tabs Title Link
641
+ *
642
+ * Echos the title link of the registered tabs
643
+ *
644
+ * @since 4.0.0
645
+ * @return array The array of registered tabs
646
+ */
647
+ public function get_settings_tabs() {
648
+ return apply_filters( 'qmn_quiz_setting_tabs', $this->settings_tabs );
649
+ }
650
+
651
+ /**
652
+ * global animatiocv array return
653
+ *
654
+ * @since 4.7.1
655
+ */
656
+ public function quiz_animation_effect() {
657
 
658
  return array(
659
  array(
704
 
705
  }
706
 
707
+ /**
708
  * converts dates into preferred date format
709
  *
710
+ * @since 7.3.3
711
+ * @param array $qsm_qna_array The array of results for the quiz
712
+ * @uses QMNQuizManager:submit_results() submits and displays results
713
+ * @uses qsm_generate_results_details_tab() generates admin results page
714
  * @return array $qsm_qna_array date formatted array of results for the quiz
715
  */
716
 
717
  public function convert_to_preferred_date_format( $qsm_qna_array ) {
718
+ global $mlwQuizMasterNext;
719
+ $quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
720
+ $qsm_quiz_settings = maybe_unserialize( $quiz_options->quiz_settings );
721
+ $qsm_quiz_options = maybe_unserialize( $qsm_quiz_settings['quiz_options'] );
722
+ $qsm_global_settings = get_option( 'qsm-quiz-settings' );
723
+ // check if preferred date format is set at quiz level or plugin level. Default to WP date format otherwise
724
+ if ( isset( $qsm_quiz_options['preferred_date_format'] ) ) {
725
+ $preferred_date_format = $qsm_quiz_options['preferred_date_format'];
726
+ } elseif ( isset( $qsm_global_settings['preferred_date_format'] ) ) {
727
+ $preferred_date_format = isset( $qsm_global_settings['preferred_date_format'] );
728
+ } else {
729
+ $preferred_date_format = get_option( 'date_format' );
730
+ }
731
+ // filter date format
732
+ $GLOBALS['qsm_date_format'] = apply_filters( 'qms_preferred_date_format', $preferred_date_format );
733
+
734
+ $qsm_qna_array = $this->convert_contacts_to_preferred_date_format( $qsm_qna_array );
735
+ $qsm_qna_array = $this->convert_answers_to_preferred_date_format( $qsm_qna_array );
736
+ $this->convert_questions_to_preferred_date_format();
737
+
738
+ return $qsm_qna_array;
739
+ }
740
+
741
+ /**
742
  * converts contacts into preferred date format
743
  *
744
+ * @since 7.3.3
745
+ * @param array $qsm_qna_array The array of results for the quiz
746
+ * @uses convert_to_preferred_date_format()
747
  * @return array $qsm_qna_array date formatted array of results for the quiz
748
  */
749
 
750
  public function convert_contacts_to_preferred_date_format( $qsm_qna_array ) {
751
 
752
+ $qsm_contact_array = $qsm_qna_array['contact'];
753
+ foreach ( $qsm_contact_array as $qsm_contact_id => $qsm_contact ) {
754
+ if ( 'date' === $qsm_contact['type'] && null !== $GLOBALS['qsm_date_format'] ) {
755
+ $qsm_qna_array['contact'][ $qsm_contact_id ]['value'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime( ( $qsm_contact['value'] ) ) );
756
+ }
757
+ }
758
+ return $qsm_qna_array;
759
  }
760
 
761
+ /**
762
  * converts answers into preferred date format
763
  *
764
+ * @since 7.3.3
765
+ * @param array $qsm_qna_array The array of results for the quiz
766
+ * @uses convert_to_preferred_date_format()
767
  * @return array $qsm_qna_array date formatted array of results for the quiz
768
  */
769
 
770
  public function convert_answers_to_preferred_date_format( $qsm_qna_array ) {
771
 
772
+ $qsm_qna_list = $qsm_qna_array['question_answers_array'];
773
+ foreach ( $qsm_qna_list as $qna_id => $qna ) {
774
+ if ( '12' === $qna['question_type'] && null !== $GLOBALS['qsm_date_format'] ) {
775
+ $qsm_qna_array['question_answers_array'][ $qna_id ]['1'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime( ( $qna['1'] ) ) );
776
+ $qsm_qna_array['question_answers_array'][ $qna_id ]['2'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime( ( $qna['2'] ) ) );
777
+ }
778
+ }
779
+ return $qsm_qna_array;
780
  }
781
 
782
+ /**
783
  * converts questions into preferred date format
784
  *
785
+ * @since 7.3.3
786
+ * @param array $qsm_qna_array The array of results for the quiz
787
+ * @uses convert_to_preferred_date_format()
788
  * @return array $qsm_qna_array date formatted array of results for the quiz
789
  */
790
 
791
+ public function convert_questions_to_preferred_date_format() {
792
+ if ( ! function_exists( 'qsm_convert_question_array_date_format' ) ) {
793
+ function qsm_convert_question_array_date_format( $questions ) {
794
+ foreach ( $questions as $question_id => $question_to_convert ) {
795
+ if ( '12' === $question_to_convert['question_type_new'] ) {
796
+ foreach ( $question_to_convert['answers'] as $answer_id => $answer_value ) {
797
+ $questions[ $question_id ]['answers'][ $answer_id ][0] = date_i18n( $GLOBALS['qsm_date_format'], strtotime( $answer_value[0] ) );
798
+ }
799
+ }
800
+ }
801
+ return $questions;
802
+ }
803
+ }
804
+ add_filter( 'qsm_load_questions_by_pages', 'qsm_convert_question_array_date_format' );
 
805
  }
806
 
807
+ /**
808
  *
809
  *
810
+ * @since 7.3.5
811
+ * @param array
812
  * @uses
813
  * @return array
814
  */
815
 
816
+ public function qsm_results_css_inliner( $html ) {
817
+
818
+ $incorrect_answer = "<span style='color:red;display:block;margin-bottom:5px;'>&#x2715;";
819
+ $correct_answer = "<span style='color:green;display:block;margin-bottom:5px;'>&#10003;";
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 );
827
+ $html = str_replace( '<span class="qsm-text-correct-option qsm-text-user-correct-answer qmn_image_option">', "$correct_answer ", $html );
828
+ $html = str_replace( '<span class="qsm-text-simple-option qmn_image_option">', "$simple_answer ", $html );
829
+ $html = str_replace( '<span class="qsm-text-correct-option qsm-text-user-correct-answer ">', "$correct_answer ", $html );
830
+ $html = str_replace( '<span class="qsm-text-simple-option ">', "$simple_answer ", $html );
831
+ $html = str_replace( '<span class="qsm-text-wrong-option ">', "$incorrect_answer ", $html );
832
+ $html = str_replace( '<span class="qsm-text-correct-option ">', "$correct_answer ", $html );
833
+ $html = str_replace( '<span class="qmn_user_incorrect_answer">', "$incorrect_answer ", $html );
834
+ $html = str_replace( '<span class="qmn_user_incorrect_answer">', "$correct_answer ", $html );
835
+ $html = str_replace( "class='qmn_question_answer", "style='margin-bottom:30px' class='", $html );
836
+
837
+ return $html;
838
+ }
839
  }
php/classes/class-qmn-quiz-creator.php CHANGED
@@ -15,10 +15,11 @@ if ( ! defined( 'ABSPATH' ) ) {
15
  class QMNQuizCreator {
16
 
17
 
 
18
  /**
19
  * QMN ID of quiz
20
  *
21
- * @var object
22
  * @since 3.7.1
23
  */
24
  private $quiz_id;
@@ -37,8 +38,8 @@ class QMNQuizCreator {
37
  /**
38
  * Sets quiz ID
39
  *
40
- * @since 3.8.1
41
- * @param int $quiz_id The ID of the quiz.
42
  * @access public
43
  * @return void
44
  */
@@ -49,7 +50,7 @@ class QMNQuizCreator {
49
  /**
50
  * Gets the quiz ID stored (for backwards compatibility)
51
  *
52
- * @since 5.0.0
53
  * @return int|false The ID of the quiz stored or false
54
  */
55
  public function get_id() {
@@ -64,8 +65,8 @@ class QMNQuizCreator {
64
  * Creates a new quiz with the default settings
65
  *
66
  * @access public
67
- * @since 3.7.1
68
- * @param string $quiz_name The name of the new quiz.
69
  * @return void
70
  */
71
  public function create_quiz( $quiz_name, $theme_id, $quiz_settings = array() ) {
@@ -201,7 +202,7 @@ class QMNQuizCreator {
201
  $mlwQuizMasterNext->theme_settings->activate_selected_theme( $new_quiz, $theme_id );
202
 
203
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your new quiz or survey has been created successfully. To begin editing, click the Edit link.', 'quiz-master-next' ), 'success' );
204
- $mlwQuizMasterNext->audit_manager->new_audit( "New Quiz/Survey Has Been Created: $quiz_name" );
205
 
206
  // Hook called after new quiz or survey has been created. Passes quiz_id to hook
207
  do_action( 'qmn_quiz_created', $new_quiz );
@@ -215,15 +216,21 @@ class QMNQuizCreator {
215
  * Deletes a quiz with the given quiz_id
216
  *
217
  * @access public
218
- * @since 3.7.1
219
  * @return void
220
  */
221
  public function delete_quiz( $quiz_id, $quiz_name ) {
222
  global $mlwQuizMasterNext;
223
  global $wpdb;
224
 
225
- $qsm_delete_from_db = isset($_POST['qsm_delete_from_db']) && "1" === sanitize_text_field( wp_unslash( $_POST['qsm_delete_from_db'] ) );
226
- $qsm_delete_questions_from_qb = isset($_POST['qsm_delete_question_from_qb']) && "1" === sanitize_text_field( wp_unslash( $_POST['qsm_delete_question_from_qb'] ) );
 
 
 
 
 
 
227
 
228
  if ( $qsm_delete_from_db ) {
229
  $qsm_delete = $wpdb->delete(
@@ -236,7 +243,7 @@ class QMNQuizCreator {
236
  array( 'quiz_id' => $quiz_id )
237
  );
238
  }
239
- }else {
240
  $qsm_delete = $wpdb->update(
241
  $wpdb->prefix . 'mlw_quizzes',
242
  array(
@@ -248,7 +255,7 @@ class QMNQuizCreator {
248
  ),
249
  array( '%d' )
250
  );
251
- $deleted = 0;
252
  if ( $qsm_delete_questions_from_qb ) {
253
  $deleted = 1;
254
  $wpdb->update(
@@ -265,32 +272,14 @@ class QMNQuizCreator {
265
  }
266
  }
267
 
268
- if ( $qsm_delete ) {
269
- $my_query = new WP_Query(
270
- array(
271
- 'post_type' => 'qsm_quiz',
272
- 'meta_key' => 'quiz_id',
273
- 'meta_value' => $quiz_id,
274
- )
275
- );
276
- if ( $my_query->have_posts() ) {
277
- while ( $my_query->have_posts() ) {
278
- $my_query->the_post();
279
- $my_post = array(
280
- 'ID' => get_the_ID(),
281
- 'post_status' => 'trash',
282
- );
283
- wp_update_post( $my_post );
284
- }
285
- }
286
- wp_reset_postdata();
287
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been deleted successfully.', 'quiz-master-next' ), 'success' );
288
- $mlwQuizMasterNext->audit_manager->new_audit( "Quiz/Survey Has Been Deleted: $quiz_name" );
289
  } else {
290
  $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0002', 'quiz-master-next' ), 'error' );
291
  $mlwQuizMasterNext->log_manager->add( 'Error 0002', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' );
292
  }
293
-
294
  // Hook called after quiz or survey is deleted. Hook passes quiz_id to function
295
  do_action( 'qmn_quiz_deleted', $quiz_id );
296
  }
@@ -299,9 +288,9 @@ class QMNQuizCreator {
299
  * Edits the name of the quiz with the given ID
300
  *
301
  * @access public
302
- * @since 3.7.1
303
- * @param int $quiz_id The ID of the quiz.
304
- * @param string $quiz_name The new name of the quiz.
305
  * @return void
306
  */
307
  public function edit_quiz_name( $quiz_id, $quiz_name ) {
@@ -320,7 +309,7 @@ class QMNQuizCreator {
320
  );
321
  if ( false !== $results ) {
322
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The name of your quiz or survey has been updated successfully.', 'quiz-master-next' ), 'success' );
323
- $mlwQuizMasterNext->audit_manager->new_audit( "Quiz/Survey Name Has Been Edited: $quiz_name" );
324
  } else {
325
  $error = $wpdb->last_error;
326
  if ( empty( $error ) ) {
@@ -341,12 +330,19 @@ class QMNQuizCreator {
341
  * Duplicates the quiz with the given ID and gives new quiz the given quiz name
342
  *
343
  * @access public
344
- * @since 3.7.1
345
  * @return void
346
  */
347
  public function duplicate_quiz( $quiz_id, $quiz_name, $is_duplicating_questions ) {
348
  global $mlwQuizMasterNext;
349
  global $wpdb;
 
 
 
 
 
 
 
350
  $current_user = wp_get_current_user();
351
  $table_name = $wpdb->prefix . 'mlw_quizzes';
352
  $logic_table = $wpdb->prefix . 'mlw_logic';
@@ -508,7 +504,7 @@ class QMNQuizCreator {
508
  $quiz_post_id = wp_insert_post( $quiz_post );
509
  add_post_meta( $quiz_post_id, 'quiz_id', $mlw_new_id );
510
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been duplicated successfully.', 'quiz-master-next' ), 'success' );
511
- $mlwQuizMasterNext->audit_manager->new_audit( "New Quiz/Survey Has Been Created: $quiz_name" );
512
  do_action( 'qmn_quiz_duplicated', $quiz_id, $mlw_new_id );
513
  } else {
514
  $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0011', 'quiz-master-next' ), 'error' );
@@ -634,7 +630,7 @@ class QMNQuizCreator {
634
  }
635
  }
636
  $update_quiz_settings['pages'] = maybe_serialize( $update_pages );
637
- // saves data in logic table first or else in quiz_settings
638
  $value_array = array();
639
  if ( is_array( $logic_rules ) && ! empty( $logic_rules ) ) {
640
  if ( is_null( $logic_table_exists ) ) {
@@ -676,10 +672,10 @@ class QMNQuizCreator {
676
  * Retrieves setting store in quiz_settings
677
  *
678
  * @deprecated 6.0.3 Use the get_quiz_setting function in the pluginHelper object.
679
- * @since 3.8.1
680
- * @access public
681
- * @param string $setting_name The slug of the setting.
682
- * @return string The value of the setting
683
  */
684
  public function get_setting( $setting_name ) {
685
  global $wpdb;
@@ -698,11 +694,11 @@ class QMNQuizCreator {
698
  * Updates setting stored in quiz_settings
699
  *
700
  * @deprecated 6.0.3 Use the update_quiz_setting function in the pluginHelper object.
701
- * @since 3.8.1
702
- * @access public
703
- * @param string $setting_name The slug of the setting.
704
- * @param mixed $setting_value The value for the setting.
705
- * @return bool True if update was successful
706
  */
707
  public function update_setting( $setting_name, $setting_value ) {
708
  global $wpdb;
@@ -734,9 +730,9 @@ class QMNQuizCreator {
734
  * Deletes setting stored in quiz_settings
735
  *
736
  * @deprecated 6.0.3
737
- * @since 3.8.1
738
- * @access public
739
- * @return void
740
  */
741
  public function delete_setting( $setting_name ) {
742
  global $wpdb;
@@ -745,7 +741,7 @@ class QMNQuizCreator {
745
  if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting_name ] ) ) {
746
  unset( $qmn_settings_array[ $setting_name ] );
747
  }
748
- $results = $wpdb->update(
749
  $wpdb->prefix . 'mlw_quizzes',
750
  array(
751
  'quiz_settings' => maybe_serialize( $qmn_settings_array ),
@@ -757,4 +753,4 @@ class QMNQuizCreator {
757
  array( '%d' )
758
  );
759
  }
760
- }
15
  class QMNQuizCreator {
16
 
17
 
18
+
19
  /**
20
  * QMN ID of quiz
21
  *
22
+ * @var object
23
  * @since 3.7.1
24
  */
25
  private $quiz_id;
38
  /**
39
  * Sets quiz ID
40
  *
41
+ * @since 3.8.1
42
+ * @param int $quiz_id The ID of the quiz.
43
  * @access public
44
  * @return void
45
  */
50
  /**
51
  * Gets the quiz ID stored (for backwards compatibility)
52
  *
53
+ * @since 5.0.0
54
  * @return int|false The ID of the quiz stored or false
55
  */
56
  public function get_id() {
65
  * Creates a new quiz with the default settings
66
  *
67
  * @access public
68
+ * @since 3.7.1
69
+ * @param string $quiz_name The name of the new quiz.
70
  * @return void
71
  */
72
  public function create_quiz( $quiz_name, $theme_id, $quiz_settings = array() ) {
202
  $mlwQuizMasterNext->theme_settings->activate_selected_theme( $new_quiz, $theme_id );
203
 
204
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your new quiz or survey has been created successfully. To begin editing, click the Edit link.', 'quiz-master-next' ), 'success' );
205
+ $mlwQuizMasterNext->audit_manager->new_audit( 'New Quiz/Survey Has Been Created', $new_quiz, '' );
206
 
207
  // Hook called after new quiz or survey has been created. Passes quiz_id to hook
208
  do_action( 'qmn_quiz_created', $new_quiz );
216
  * Deletes a quiz with the given quiz_id
217
  *
218
  * @access public
219
+ * @since 3.7.1
220
  * @return void
221
  */
222
  public function delete_quiz( $quiz_id, $quiz_name ) {
223
  global $mlwQuizMasterNext;
224
  global $wpdb;
225
 
226
+ $qsm_delete_from_db = isset( $_POST['qsm_delete_from_db'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['qsm_delete_from_db'] ) );
227
+ $qsm_delete_questions_from_qb = isset( $_POST['qsm_delete_question_from_qb'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['qsm_delete_question_from_qb'] ) );
228
+
229
+ $quiz_post_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = '$quiz_id'" );
230
+ if ( empty( $quiz_post_id ) || ! current_user_can( 'delete_post', $quiz_post_id ) ) {
231
+ $mlwQuizMasterNext->alertManager->newAlert( __( 'Sorry, you are not allowed to delete this quiz.', 'quiz-master-next' ), 'error' );
232
+ return;
233
+ }
234
 
235
  if ( $qsm_delete_from_db ) {
236
  $qsm_delete = $wpdb->delete(
243
  array( 'quiz_id' => $quiz_id )
244
  );
245
  }
246
+ } else {
247
  $qsm_delete = $wpdb->update(
248
  $wpdb->prefix . 'mlw_quizzes',
249
  array(
255
  ),
256
  array( '%d' )
257
  );
258
+ $deleted = 0;
259
  if ( $qsm_delete_questions_from_qb ) {
260
  $deleted = 1;
261
  $wpdb->update(
272
  }
273
  }
274
 
275
+ if ( $qsm_delete && ! empty( $quiz_post_id ) ) {
276
+ wp_trash_post( $quiz_post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been deleted successfully.', 'quiz-master-next' ), 'success' );
278
+ $mlwQuizMasterNext->audit_manager->new_audit( "Quiz/Survey Has Been Deleted: $quiz_name", $quiz_id, '' );
279
  } else {
280
  $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0002', 'quiz-master-next' ), 'error' );
281
  $mlwQuizMasterNext->log_manager->add( 'Error 0002', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error' );
282
  }
 
283
  // Hook called after quiz or survey is deleted. Hook passes quiz_id to function
284
  do_action( 'qmn_quiz_deleted', $quiz_id );
285
  }
288
  * Edits the name of the quiz with the given ID
289
  *
290
  * @access public
291
+ * @since 3.7.1
292
+ * @param int $quiz_id The ID of the quiz.
293
+ * @param string $quiz_name The new name of the quiz.
294
  * @return void
295
  */
296
  public function edit_quiz_name( $quiz_id, $quiz_name ) {
309
  );
310
  if ( false !== $results ) {
311
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The name of your quiz or survey has been updated successfully.', 'quiz-master-next' ), 'success' );
312
+ $mlwQuizMasterNext->audit_manager->new_audit( 'Quiz/Survey Name Has Been Edited', $quiz_id, '' );
313
  } else {
314
  $error = $wpdb->last_error;
315
  if ( empty( $error ) ) {
330
  * Duplicates the quiz with the given ID and gives new quiz the given quiz name
331
  *
332
  * @access public
333
+ * @since 3.7.1
334
  * @return void
335
  */
336
  public function duplicate_quiz( $quiz_id, $quiz_name, $is_duplicating_questions ) {
337
  global $mlwQuizMasterNext;
338
  global $wpdb;
339
+
340
+ $quiz_post_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = '$quiz_id'" );
341
+ if ( empty( $quiz_post_id ) || ! current_user_can( 'edit_post', $quiz_post_id ) ) {
342
+ $mlwQuizMasterNext->alertManager->newAlert( __( 'Sorry, you are not allowed to duplicate this quiz.', 'quiz-master-next' ), 'error' );
343
+ return;
344
+ }
345
+
346
  $current_user = wp_get_current_user();
347
  $table_name = $wpdb->prefix . 'mlw_quizzes';
348
  $logic_table = $wpdb->prefix . 'mlw_logic';
504
  $quiz_post_id = wp_insert_post( $quiz_post );
505
  add_post_meta( $quiz_post_id, 'quiz_id', $mlw_new_id );
506
  $mlwQuizMasterNext->alertManager->newAlert( __( 'Your quiz or survey has been duplicated successfully.', 'quiz-master-next' ), 'success' );
507
+ $mlwQuizMasterNext->audit_manager->new_audit( 'New Quiz/Survey Has Been Created', $mlw_new_id, '' );
508
  do_action( 'qmn_quiz_duplicated', $quiz_id, $mlw_new_id );
509
  } else {
510
  $mlwQuizMasterNext->alertManager->newAlert( __( 'There has been an error in this action. Please share this with the developer. Error Code: 0011', 'quiz-master-next' ), 'error' );
630
  }
631
  }
632
  $update_quiz_settings['pages'] = maybe_serialize( $update_pages );
633
+ // saves data in logic table first or else in quiz_settings.
634
  $value_array = array();
635
  if ( is_array( $logic_rules ) && ! empty( $logic_rules ) ) {
636
  if ( is_null( $logic_table_exists ) ) {
672
  * Retrieves setting store in quiz_settings
673
  *
674
  * @deprecated 6.0.3 Use the get_quiz_setting function in the pluginHelper object.
675
+ * @since 3.8.1
676
+ * @access public
677
+ * @param string $setting_name The slug of the setting.
678
+ * @return string The value of the setting
679
  */
680
  public function get_setting( $setting_name ) {
681
  global $wpdb;
694
  * Updates setting stored in quiz_settings
695
  *
696
  * @deprecated 6.0.3 Use the update_quiz_setting function in the pluginHelper object.
697
+ * @since 3.8.1
698
+ * @access public
699
+ * @param string $setting_name The slug of the setting.
700
+ * @param mixed $setting_value The value for the setting.
701
+ * @return bool True if update was successful
702
  */
703
  public function update_setting( $setting_name, $setting_value ) {
704
  global $wpdb;
730
  * Deletes setting stored in quiz_settings
731
  *
732
  * @deprecated 6.0.3
733
+ * @since 3.8.1
734
+ * @access public
735
+ * @return void
736
  */
737
  public function delete_setting( $setting_name ) {
738
  global $wpdb;
741
  if ( is_array( $qmn_settings_array ) && isset( $qmn_settings_array[ $setting_name ] ) ) {
742
  unset( $qmn_settings_array[ $setting_name ] );
743
  }
744
+ $results = $wpdb->update(
745
  $wpdb->prefix . 'mlw_quizzes',
746
  array(
747
  'quiz_settings' => maybe_serialize( $qmn_settings_array ),
753
  array( '%d' )
754
  );
755
  }
756
+ }
php/classes/class-qmn-quiz-manager.php CHANGED
@@ -15,14 +15,15 @@ if ( ! defined( 'ABSPATH' ) ) {
15
  */
16
  class QMNQuizManager {
17
 
 
18
  /**
19
  * $common_css
20
  *
21
- * @var string
22
  * @since 7.3.5
23
  */
24
- public $common_css = QSM_PLUGIN_CSS_URL.'/common.css';
25
- public $mathjax_url = QSM_PLUGIN_JS_URL.'/mathjax/tex-mml-chtml.js';
26
  public $mathjax_version = '3.2.0';
27
 
28
  protected $qsm_background_email;
@@ -31,8 +32,8 @@ class QMNQuizManager {
31
  *
32
  * Call functions within class
33
  *
34
- * @since 4.0.0
35
- * @uses QMNQuizManager::add_hooks() Adds actions to hooks and filters
36
  * @return void
37
  */
38
  public function __construct() {
@@ -44,7 +45,7 @@ class QMNQuizManager {
44
  *
45
  * Adds functions to relavent hooks and filters
46
  *
47
- * @since 4.0.0
48
  * @return void
49
  */
50
  public function add_hooks() {
@@ -57,6 +58,12 @@ class QMNQuizManager {
57
  add_action( 'wp_ajax_nopriv_qsm_get_quiz_to_reload', array( $this, 'qsm_get_quiz_to_reload' ) );
58
  add_action( 'wp_ajax_qsm_get_question_quick_result', array( $this, 'qsm_get_question_quick_result' ) );
59
  add_action( 'wp_ajax_nopriv_qsm_get_question_quick_result', array( $this, 'qsm_get_question_quick_result' ) );
 
 
 
 
 
 
60
  // Upload file of file upload question type
61
  add_action( 'wp_ajax_qsm_upload_image_fd_question', array( $this, 'qsm_upload_image_fd_question' ) );
62
  add_action( 'wp_ajax_nopriv_qsm_upload_image_fd_question', array( $this, 'qsm_upload_image_fd_question' ) );
@@ -123,10 +130,10 @@ class QMNQuizManager {
123
  }
124
 
125
  $uploaded_file['name'] = 'qsmfileupload_' . uniqid() . '_' . str_replace( '-', '_', $file_name );
126
- $upload_overrides = array(
127
  'test_form' => false,
128
  );
129
- $movefile = wp_handle_upload( $uploaded_file, $upload_overrides );
130
  if ( $movefile && ! isset( $movefile['error'] ) ) {
131
  // Prepare an array of post data for the attachment.
132
  $attachment = array(
@@ -139,7 +146,7 @@ class QMNQuizManager {
139
  // Insert the attachment.
140
  $attach_id = wp_insert_attachment( $attachment, $movefile['file'], 0 );
141
  if ( $attach_id ) {
142
- require_once ABSPATH . 'wp-admin/includes/image.php';
143
  $attach_data = wp_generate_attachment_metadata( $attach_id, $movefile['file'] );
144
  wp_update_attachment_metadata( $attach_id, $attach_data );
145
  }
@@ -221,17 +228,63 @@ class QMNQuizManager {
221
  wp_die();
222
  }
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  /**
225
  * Generates Content For Quiz Shortcode
226
  *
227
  * Generates the content for the [mlw_quizmaster] shortcode
228
  *
229
- * @since 4.0.0
230
- * @param array $atts The attributes passed from the shortcode.
231
- * @uses QMNQuizManager:load_questions() Loads questions
232
- * @uses QMNQuizManager:create_answer_array() Prepares answers
233
- * @uses QMNQuizManager:display_quiz() Generates and prepares quiz page
234
- * @uses QMNQuizManager:display_results() Generates and prepares results page
235
  * @return string The content for the shortcode
236
  */
237
  public function display_shortcode( $atts ) {
@@ -244,7 +297,7 @@ class QMNQuizManager {
244
  $atts
245
  );
246
 
247
- $quiz = intval( $args['quiz'] );
248
  $question_amount = intval( $args['question_amount'] );
249
 
250
  ob_start();
@@ -256,9 +309,9 @@ class QMNQuizManager {
256
  wp_enqueue_style( 'dashicons' );
257
  wp_enqueue_script( 'jquery' );
258
  wp_enqueue_script( 'jquery-ui-tooltip' );
259
- wp_enqueue_script( 'qsm_quiz', QSM_PLUGIN_JS_URL.'/qsm-quiz.js', array( 'wp-util', 'underscore', 'jquery', 'jquery-ui-tooltip' ), $mlwQuizMasterNext->version, false );
260
- wp_enqueue_script( 'qsm_common', QSM_PLUGIN_JS_URL.'/qsm-common.js', array(), $mlwQuizMasterNext->version, true );
261
- wp_enqueue_script( 'math_jax',$this->mathjax_url , false , $this->mathjax_version , true );
262
  $result_unique_id = sanitize_text_field( wp_unslash( $_GET['result_id'] ) );
263
  $query = $wpdb->prepare( "SELECT result_id FROM {$wpdb->prefix}mlw_results WHERE unique_id = %s", $result_unique_id );
264
  $result = $wpdb->get_row( $query, ARRAY_A );
@@ -292,7 +345,7 @@ class QMNQuizManager {
292
  /**
293
  * Filter Quiz Options before Quiz Display
294
  */
295
- $qmn_quiz_options = apply_filters('qsm_shortcode_quiz_options', $qmn_quiz_options);
296
 
297
  // If quiz options isn't found, stop function.
298
  if ( is_null( $qmn_quiz_options ) || empty( $qmn_quiz_options->quiz_name ) ) {
@@ -303,7 +356,7 @@ class QMNQuizManager {
303
  // The quiz_stye is misspelled because it has always been misspelled and fixing it would break many sites :(.
304
  if ( 'default' == $qmn_quiz_options->theme_selected ) {
305
  $return_display .= '<style type="text/css">' . preg_replace( '#<script(.*?)>(.*?)</script>#is', '', htmlspecialchars_decode( $qmn_quiz_options->quiz_stye ) ) . '</style>';
306
- wp_enqueue_style( 'qmn_quiz_style', QSM_PLUGIN_CSS_URL.'/qmn_quiz.css', array(), $mlwQuizMasterNext->version );
307
  wp_style_add_data( 'qmn_quiz_style', 'rtl', 'replace' );
308
  } else {
309
  $registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates( $qmn_quiz_options->theme_selected );
@@ -316,10 +369,10 @@ class QMNQuizManager {
316
  } elseif ( $registered_template && file_exists( get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'] ) ) {
317
  wp_enqueue_style( 'qmn_quiz_template', get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'], array(), $mlwQuizMasterNext->version );
318
  } else {
319
- echo "<style type='text/css'>" . wp_kses_post( htmlspecialchars_decode( $qmn_quiz_options->quiz_stye ) ) . "</style>";
320
  }
321
  }
322
- wp_enqueue_style( 'qmn_quiz_animation_style', QSM_PLUGIN_CSS_URL.'/animate.css', array(), $mlwQuizMasterNext->version );
323
  wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
324
  wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
325
  wp_enqueue_style( 'dashicons' );
@@ -337,8 +390,8 @@ class QMNQuizManager {
337
  'quiz_system' => $qmn_quiz_options->system,
338
  'user_ip' => $this->get_user_ip(),
339
  );
340
- $qpages = array();
341
- $qpages_arr = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'qpages', array() );
342
  if ( ! empty( $qpages_arr ) ) {
343
  foreach ( $qpages_arr as $key => $qpage ) {
344
  unset( $qpage['questions'] );
@@ -365,7 +418,7 @@ class QMNQuizManager {
365
  'quick_result_wrong_answer_text' => sanitize_text_field( $qmn_quiz_options->quick_result_wrong_answer_text ),
366
  'quiz_processing_message' => $qmn_quiz_options->quiz_processing_message,
367
  'not_allow_after_expired_time' => $qmn_quiz_options->not_allow_after_expired_time,
368
- 'scheduled_time_end' => strtotime($qmn_quiz_options->scheduled_time_end),
369
  );
370
 
371
  $return_display = apply_filters( 'qmn_begin_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables, $atts );
@@ -379,8 +432,8 @@ class QMNQuizManager {
379
 
380
  $qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables, $atts );
381
 
382
- $return_display .= ob_get_clean();
383
- $return_display = apply_filters( 'qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables, $atts );
384
  $qmn_quiz_data[ $qmn_json_data['quiz_id'] ] = $qmn_filtered_json;
385
  wp_localize_script( 'qsm_quiz', 'qmn_quiz_data', $qmn_quiz_data );
386
  }
@@ -407,11 +460,11 @@ class QMNQuizManager {
407
  global $wpdb;
408
  $result_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_results WHERE result_id = %d", $id ), ARRAY_A );
409
  if ( $result_data ) {
410
- wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version);
411
  wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
412
  wp_enqueue_style( 'dashicons' );
413
- wp_enqueue_style( 'qsm_primary_css', plugins_url( '../../templates/qmn_primary.css', __FILE__ ), array(), $mlwQuizMasterNext->version);
414
- wp_enqueue_script( 'math_jax', $this->mathjax_url, false , $this->mathjax_version , true );
415
  $quiz_result = maybe_unserialize( $result_data['quiz_results'] );
416
  $response_data = array(
417
  'quiz_id' => $result_data['quiz_id'],
@@ -452,12 +505,12 @@ class QMNQuizManager {
452
  *
453
  * Retrieves the questions from the database
454
  *
455
- * @since 4.0.0
456
- * @param int $quiz_id The id for the quiz.
457
- * @param array $quiz_options The database row for the quiz.
458
- * @param bool $is_quiz_page If the page being loaded is the quiz page or not.
459
- * @param int $question_amount The amount of questions entered using the shortcode attribute.
460
- * @return array The questions for the quiz
461
  * @deprecated 5.2.0 Use new class: QSM_Questions instead
462
  */
463
  public function load_questions( $quiz_id, $quiz_options, $is_quiz_page, $question_amount = 0 ) {
@@ -465,11 +518,11 @@ class QMNQuizManager {
465
  // Prepare variables.
466
  global $wpdb;
467
  global $mlwQuizMasterNext;
468
- $questions = array();
469
- $order_by_sql = 'ORDER BY question_order ASC';
470
- $limit_sql = '';
471
- $big_array = array();
472
- $exploded_arr = array();
473
  $multiple_category_system = false;
474
  // check if multiple category is enabled.
475
  $enabled = get_option( 'qsm_multiple_category_enabled' );
@@ -485,16 +538,16 @@ class QMNQuizManager {
485
  if ( $categories ) {
486
  $exploded_arr = explode( ',', $quiz_options->randon_category );
487
  if ( ! $multiple_category_system ) {
488
- $cat_str = "'" . implode( "', '", $exploded_arr ) . "'";
489
- $cat_query = " AND category IN ( $cat_str ) ";
490
  } else {
491
- $exploded_arr = array_map( 'intval' , $exploded_arr );
492
  }
493
  }
494
  }
495
 
496
  // Check if we should load all questions or only a selcted amount.
497
- if ( $is_quiz_page && ( 0 != $quiz_options->question_from_total || 0 !== $question_amount ) ) {
498
  if ( 0 !== $question_amount ) {
499
  $limit_sql = " LIMIT $question_amount";
500
  } else {
@@ -505,11 +558,11 @@ class QMNQuizManager {
505
  // If using newer pages system from 5.2.
506
  $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
507
  // Get all question IDs needed.
508
- $total_pages = count( $pages );
509
  $category_question_ids = array();
510
  if ( $multiple_category_system && ! empty( $exploded_arr ) ) {
511
- $term_ids = implode( ', ', $exploded_arr );
512
- $query = $wpdb->prepare( "SELECT DISTINCT question_id FROM {$wpdb->prefix}mlw_question_terms WHERE quiz_id = %d AND term_id IN (%1s)", $quiz_id, $term_ids);
513
  $question_data = $wpdb->get_results( $query, ARRAY_N );
514
  foreach ( $question_data as $q_data ) {
515
  $category_question_ids[] = $q_data[0];
@@ -520,7 +573,7 @@ class QMNQuizManager {
520
  for ( $i = 0; $i < $total_pages; $i++ ) {
521
  foreach ( $pages[ $i ] as $question ) {
522
  if ( ! empty( $category_question_ids ) ) {
523
- if ( in_array( intval( $question ), array_map('intval', $category_question_ids ), true ) ) {
524
  $question_ids[] = intval( $question );
525
  }
526
  } else {
@@ -529,33 +582,33 @@ class QMNQuizManager {
529
  }
530
  }
531
 
532
- //check If we should load a specific number of question
533
  if ( 0 != $quiz_options->question_per_category && $is_quiz_page ) {
534
- $categories = QSM_Questions::get_quiz_categories( $quiz_id );
535
- $category_ids = (isset($categories['list']) ? array_keys($categories['list']) : array());
536
- $categories_tree = (isset($categories['tree']) ? $categories['tree'] : array());
537
- if ( ! empty($category_ids) ) {
538
- $term_ids = implode(',', $category_ids);
539
- $term_ids = ('' !== $quiz_options->randon_category) ? $quiz_options->randon_category : $term_ids;
540
- $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 );
541
- $random = array();
542
- if ( ! empty($tq_ids) ) {
543
  $term_data = array();
544
  foreach ( $tq_ids as $key => $val ) {
545
  $term_data[ $val['term_id'] ][] = $val['question_id'];
546
  }
547
  if ( '' === $quiz_options->randon_category ) {
548
  foreach ( $categories_tree as $cat ) {
549
- if ( ! empty($cat->children) ) {
550
- unset($term_data[ $cat->term_id ]);
551
  }
552
  }
553
  }
554
  foreach ( $term_data as $tv ) {
555
  if ( 1 == $quiz_options->randomness_order || 2 == $quiz_options->randomness_order ) {
556
- shuffle($tv);
557
  }
558
- $random = array_merge($random, array_slice(array_unique($tv), 0, $quiz_options->question_per_category));
559
  }
560
  }
561
  $question_ids = array_unique( $random );
@@ -564,13 +617,12 @@ class QMNQuizManager {
564
  $question_ids = apply_filters( 'qsm_load_questions_ids', $question_ids, $quiz_id, $quiz_options );
565
  $question_sql = implode( ', ', $question_ids );
566
 
567
- $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_questions WHERE question_id IN (%1s) %2s %3s %4s", $question_sql, $cat_query, $order_by_sql, $limit_sql );
568
- $questions = $wpdb->get_results( stripslashes( $query ) );
569
 
570
  // If we are not using randomization, we need to put the questions in the order of the new question editor.
571
  // If a user has saved the pages in the question editor but still uses the older pagination options
572
  // Then they will make it here. So, we need to order the questions based on the new editor.
573
-
574
  if ( 1 != $quiz_options->randomness_order && 2 != $quiz_options->randomness_order && 0 == $quiz_options->question_per_category ) {
575
  $ordered_questions = array();
576
  foreach ( $questions as $question ) {
@@ -594,7 +646,7 @@ class QMNQuizManager {
594
  $questions = apply_filters( 'qsm_load_questions_filter', $questions, $quiz_id, $quiz_options );
595
 
596
  // Create question ids array
597
- $qsm_random_que_ids = array_column( $questions,'question_id' );
598
  update_option( 'qsm_random_que_ids', $qsm_random_que_ids );
599
 
600
  // Returns an array of all the loaded questions.
@@ -606,10 +658,10 @@ class QMNQuizManager {
606
  *
607
  * Prepares or creates the answer array for the quiz
608
  *
609
- * @since 4.0.0
610
- * @param array $questions The questions for the quiz.
611
- * @param bool $is_ajax Pass true if this is an ajax call.
612
- * @return array The answers for the quiz
613
  * @deprecated 5.2.0 Use new class: QSM_Questions instead
614
  */
615
  public function create_answer_array( $questions, $is_ajax = false ) {
@@ -619,7 +671,7 @@ class QMNQuizManager {
619
  $question_list = array();
620
  foreach ( $questions as $mlw_question_info ) {
621
  $question_list[ $mlw_question_info->question_id ] = get_object_vars( $mlw_question_info );
622
- $mlw_qmn_answer_array_each = maybe_unserialize( $mlw_question_info->answer_array );
623
  if ( is_array( $mlw_qmn_answer_array_each ) ) {
624
  $mlw_qmn_answer_arrays[ $mlw_question_info->question_id ] = $mlw_qmn_answer_array_each;
625
  $question_list[ $mlw_question_info->question_id ]['answers'] = $mlw_qmn_answer_array_each;
@@ -650,14 +702,14 @@ class QMNQuizManager {
650
  *
651
  * Generates the content for the quiz page part of the shortcode
652
  *
653
- * @since 4.0.0
654
- * @param array $options The database row of the quiz.
655
- * @param array $quiz_data The array of results for the quiz.
656
- * @param int $question_amount The number of questions to load for quiz.
657
- * @uses QMNQuizManager:display_begin_section() Creates display for beginning section
658
- * @uses QMNQuizManager:display_questions() Creates display for questions
659
- * @uses QMNQuizManager:display_comment_section() Creates display for comment section
660
- * @uses QMNQuizManager:display_end_section() Creates display for end section
661
  * @return string The content for the quiz page section
662
  */
663
  public function display_quiz( $options, $quiz_data, $question_amount ) {
@@ -672,7 +724,7 @@ class QMNQuizManager {
672
  wp_enqueue_script( 'jquery' );
673
  wp_enqueue_script( 'jquery-ui-core' );
674
  wp_enqueue_script( 'jquery-ui-tooltip' );
675
- wp_enqueue_style( 'jquery-redmond-theme', QSM_PLUGIN_CSS_URL.'/jquery-ui.css',array(), $mlwQuizMasterNext->version );
676
 
677
  global $qmn_json_data;
678
  $qmn_json_data['error_messages'] = array(
@@ -682,16 +734,16 @@ class QMNQuizManager {
682
  'empty' => sanitize_text_field( $options->empty_error_text ),
683
  );
684
 
685
- wp_enqueue_script( 'progress-bar', QSM_PLUGIN_JS_URL.'/progressbar.min.js',array(),'1.1.0',true);
686
  wp_enqueue_script( 'jquery-ui-slider' );
687
- wp_enqueue_script( 'jquery-ui-slider-rtl-js', QSM_PLUGIN_JS_URL.'/jquery.ui.slider-rtl.js', array(), $mlwQuizMasterNext->version, true);
688
- wp_enqueue_style( 'jquery-ui-slider-rtl-css', QSM_PLUGIN_CSS_URL.'/jquery.ui.slider-rtl.css', array(), $mlwQuizMasterNext->version );
689
  wp_enqueue_script( 'jquery-touch-punch' );
690
- wp_enqueue_style( 'qsm_model_css', QSM_PLUGIN_CSS_URL.'/qsm-admin.css', array(), $mlwQuizMasterNext->version );
691
  wp_style_add_data( 'qsm_model_css', 'rtl', 'replace' );
692
- wp_enqueue_script( 'qsm_model_js', QSM_PLUGIN_JS_URL.'/micromodal.min.js',array(), $mlwQuizMasterNext->version, false);
693
- wp_enqueue_script( 'qsm_quiz', QSM_PLUGIN_JS_URL.'/qsm-quiz.js', array( 'wp-util', 'underscore', 'jquery', 'jquery-ui-tooltip', 'progress-bar' ), $mlwQuizMasterNext->version, false );
694
- wp_enqueue_script( 'qsm_common', QSM_PLUGIN_JS_URL.'/qsm-common.js', array(), $mlwQuizMasterNext->version, true );
695
  wp_localize_script(
696
  'qsm_quiz',
697
  'qmn_ajax_object',
@@ -704,7 +756,7 @@ class QMNQuizManager {
704
  ),
705
  )
706
  );
707
- wp_enqueue_script( 'math_jax', $this->mathjax_url, array() , $this->mathjax_version , true );
708
  global $qmn_total_questions;
709
  $qmn_total_questions = 0;
710
  global $mlw_qmn_section_count;
@@ -713,7 +765,8 @@ class QMNQuizManager {
713
  // $saved_quiz_theme = $mlwQuizMasterNext->quiz_settings->get_setting('quiz_new_theme');
714
  $saved_quiz_theme = $mlwQuizMasterNext->theme_settings->get_active_quiz_theme_path( $options->quiz_id );
715
  $randomness_class = 0 === intval( $options->randomness_order ) ? '' : 'random';
716
- ?><div class='qsm-quiz-container qmn_quiz_container mlw_qmn_quiz <?php echo esc_attr( $auto_pagination_class ); ?> quiz_theme_<?php echo esc_attr( $saved_quiz_theme ." ".$randomness_class ); ?> '><?php
 
717
  // Get quiz post based on quiz id
718
  $args = array(
719
  'posts_per_page' => 1,
@@ -739,10 +792,12 @@ class QMNQuizManager {
739
  }
740
  echo apply_filters( 'qsm_display_before_form', '', $options, $quiz_data );
741
  $quiz_form_action = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
742
- ?><form name="quizForm<?php echo esc_attr( $quiz_data['quiz_id'] ); ?>" id="quizForm<?php echo esc_attr( $quiz_data['quiz_id'] ); ?>" action="<?php echo esc_url( $quiz_form_action ); ?>" method="POST" class="qsm-quiz-form qmn_quiz_form mlw_quiz_form" novalidate enctype="multipart/form-data">
 
743
  <input type="hidden" name="qsm_hidden_questions" id="qsm_hidden_questions" value="">
744
  <div id="mlw_error_message" class="qsm-error-message qmn_error_message_section"></div>
745
- <span id="mlw_top_of_quiz"></span><?php
 
746
  echo apply_filters( 'qmn_begin_quiz_form', '', $options, $quiz_data );
747
  // If deprecated pagination setting is not used, use new system...
748
  $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
@@ -750,8 +805,8 @@ class QMNQuizManager {
750
  $this->display_pages( $options, $quiz_data );
751
  } else {
752
  // ... else, use older system.
753
- $questions = $this->load_questions( $quiz_data['quiz_id'], $options, true, $question_amount );
754
- $answers = $this->create_answer_array( $questions );
755
  $this->display_begin_section( $options, $quiz_data );
756
  echo apply_filters( 'qmn_begin_quiz_questions', '', $options, $quiz_data );
757
  $this->display_questions( $options, $questions, $answers );
@@ -767,14 +822,19 @@ class QMNQuizManager {
767
  <input type="hidden" name="timer" id="timer" value="0" />
768
  <input type="hidden" name="timer_ms" id="timer_ms" value="0"/>
769
  <input type="hidden" class="qmn_quiz_id" name="qmn_quiz_id" id="qmn_quiz_id" value="<?php echo esc_attr( $quiz_data['quiz_id'] ); ?>" />
770
- <input type='hidden' name='complete_quiz' value='confirmation' /><?php
771
- if ( isset( $_GET['payment_id'] ) && '' !== $_GET['payment_id'] ) {
772
- $payment_id = sanitize_text_field( wp_unslash( $_GET['payment_id'] ) );
773
- ?><input type="hidden" name="main_payment_id" value="<?php echo esc_attr( $payment_id ); ?>" /><?php
774
- }
775
- echo apply_filters( 'qmn_end_quiz_form', '', $options, $quiz_data );
776
- ?></form>
777
- </div><?php
 
 
 
 
 
778
 
779
  echo apply_filters( 'qmn_end_quiz', '', $options, $quiz_data );
780
  }
@@ -782,9 +842,9 @@ class QMNQuizManager {
782
  /**
783
  * Creates the pages of content for the quiz/survey
784
  *
785
- * @since 5.2.0
786
- * @param array $options The settings for the quiz.
787
- * @param array $quiz_data The array of quiz data.
788
  * @return string The HTML for the pages
789
  */
790
  public function display_pages( $options, $quiz_data ) {
@@ -797,7 +857,7 @@ class QMNQuizManager {
797
  $contact_fields = QSM_Contact_Manager::load_fields();
798
  $animation_effect = isset( $options->quiz_animation ) && '' !== $options->quiz_animation ? ' animated ' . $options->quiz_animation : '';
799
  $enable_pagination_quiz = isset( $options->enable_pagination_quiz ) && 1 == $options->enable_pagination_quiz ? true : false;
800
-
801
  if ( count( $pages ) > 1 && ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) ) {
802
  $qmn_json_data['first_page'] = true;
803
  $message_before = wpautop( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ) );
@@ -806,18 +866,18 @@ class QMNQuizManager {
806
  <section class="qsm-page <?php echo esc_attr( $animation_effect ); ?>">
807
  <div class="quiz_section quiz_begin">
808
  <div class='qsm-before-message mlw_qmn_message_before'>
809
- <?php
810
- $editor_text = $wp_embed->run_shortcode( $message_before );
811
- $editor_text = preg_replace( '/\s*[\w\/:\.]*youtube.com\/watch\?v=([\w]+)([\w\*\-\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $editor_text );
812
- echo do_shortcode( wp_kses_post( $editor_text ) );
813
- ?>
814
  </div>
815
- <?php
816
- if ( 0 == $options->contact_info_location ) {
817
- echo QSM_Contact_Manager::display_fields( $options );
818
- }
819
- do_action('qsm_after_begin_message', $options, $quiz_data);
820
- ?>
821
  </div>
822
  </section>
823
  <?php
@@ -827,131 +887,137 @@ class QMNQuizManager {
827
  if ( 1 == count( $pages ) ) {
828
  ?>
829
  <section class="qsm-page <?php echo esc_attr( $animation_effect ); ?>">
830
- <?php
831
- if ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) {
832
- $qmn_json_data['first_page'] = false;
833
- $message_before = wpautop( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ) );
834
- $message_before = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_before, $quiz_data );
835
- ?>
836
  <div class="quiz_section quiz_begin">
837
  <div class='qsm-before-message mlw_qmn_message_before'>
838
- <?php
839
- $editor_text = $wp_embed->run_shortcode( $message_before );
840
- $editor_text = preg_replace( '/\s*[\w\/:\.]*youtube.com\/watch\?v=([\w]+)([\w\*\-\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $editor_text );
841
- echo do_shortcode( wp_kses_post( $editor_text ) );
842
- ?>
843
  </div>
844
- <?php
845
- if ( 0 == $options->contact_info_location ) {
846
- echo QSM_Contact_Manager::display_fields( $options );
847
- }
848
- ?>
849
- </div>
850
- <?php
851
  }
852
- foreach ( $pages[0] as $question_id ) {
853
- $question_list .= $question_id . 'Q';
854
- $question = $questions[ $question_id ];
855
- $category_class = '';
856
- if ( ! empty( $question['multicategories'] ) ) {
857
- foreach ( $question['multicategories'] as $cat ) {
858
- $category_class .= ' category-section-id-c' . esc_attr( $cat );
859
- }
 
 
 
860
  }
 
 
 
 
 
 
861
  ?>
862
- <div class='quiz_section qsm-question-wrapper question-section-id-<?php echo esc_attr( $question_id ); ?> <?php echo esc_attr($category_class);?>'
863
- data-qid="<?php echo esc_attr($question_id); ?>">
864
- <?php
865
- $mlwQuizMasterNext->pluginHelper->display_question( $question['question_type_new'], $question_id, $options );
866
- if ( 0 == $question['comments'] ) { ?>
867
- <input type="text" class="qsm-question-comment qsm-question-comment-small mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" />
868
- <?php }
869
- if ( 2 == $question['comments'] ) { ?>
870
- <textarea class="qsm-question-comment qsm-question-comment-large mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" ></textarea>
871
- <?php }
872
- // Checks if a hint is entered.
873
- if ( ! empty( $question['hints'] ) ) {
874
- echo '<div class="qsm-hint qsm_hint mlw_qmn_hint_link qsm_tooltip">' . wp_kses_post( $options->hint_text ) . '<span class="qsm_tooltiptext">' . wp_kses_post( $question['hints'] ) . '</span></div>';
875
- }
876
- ?>
877
- </div>
878
  <?php
879
  }
880
- if ( 0 == $options->comment_section ) {
881
- $message_comments = wpautop( htmlspecialchars_decode( $options->message_comment, ENT_QUOTES ) );
882
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
883
  <div class="quiz_section quiz_begin">
884
  <label for='mlwQuizComments' class='qsm-comments-label mlw_qmn_comment_section_text'><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data ); ?></label>
885
  <textarea id='mlwQuizComments' name='mlwQuizComments' class='qsm-comments qmn_comment_section'></textarea>
886
  </div>
887
- <?php
888
- }
889
- if ( ! empty( $options->message_end_template ) || ( 1 == $options->contact_info_location && $contact_fields ) ) {
890
- $message_after = wpautop( htmlspecialchars_decode( $options->message_end_template, ENT_QUOTES ) );
891
- ?>
892
  <div class="quiz_section">
893
  <div class='qsm-after-message mlw_qmn_message_end'><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data ); ?></div>
894
- <?php
895
- if ( 1 == $options->contact_info_location ) {
896
- echo QSM_Contact_Manager::display_fields( $options );
897
- }
898
- ?>
899
- </div>
900
- <?php
901
  }
902
  ?>
 
 
 
 
903
  </section>
904
- <?php
905
  } else {
906
  $total_pages_count = count( $pages );
907
  $pages_count = 1;
908
  foreach ( $pages as $key => $page ) {
909
- $qpage = ( isset( $qpages[ $key ] ) ? $qpages[ $key ] : array() );
910
- $qpage_id = ( isset( $qpage['id'] ) ? $qpage['id'] : $key );
911
- $page_key = ( isset( $qpage['pagekey'] ) ? $qpage['pagekey'] : $key );
912
- $hide_prevbtn = ( isset( $qpage['hide_prevbtn'] ) ? $qpage['hide_prevbtn'] : 0 );
913
  ?>
914
  <section class="qsm-page <?php echo esc_attr( $animation_effect ); ?> qsm-page-<?php echo esc_attr( $qpage_id ); ?>"
915
  data-pid="<?php echo esc_attr( $qpage_id ); ?>" data-prevbtn="<?php echo esc_attr( $hide_prevbtn ); ?>" style='display: none;'>
916
- <?php do_action( 'qsm_action_before_page', $qpage_id, $qpage ); ?>
917
- <?php
918
- foreach ( $page as $question_id ) {
919
- $question_list .= $question_id . 'Q';
920
- $question = $questions[ $question_id ];
921
- $category_class = '';
922
- if ( ! empty( $question['multicategories'] ) ) {
923
- foreach ( $question['multicategories'] as $cat ) {
924
- $category_class .= ' category-section-id-c' . esc_attr( $cat );
925
- }
926
  }
 
 
 
 
 
 
927
  ?>
928
- <div class='quiz_section qsm-question-wrapper question-section-id-<?php echo esc_attr( $question_id ); ?> <?php echo esc_attr($category_class);?>'
929
- data-qid='<?php echo esc_attr($question_id); ?>'>
930
- <?php
931
- $mlwQuizMasterNext->pluginHelper->display_question( $question['question_type_new'], $question_id, $options );
932
- if ( 0 == $question['comments'] ) { ?>
933
- <input type="text" class="qsm-question-comment qsm-question-comment-small mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" />";
934
- <?php }
935
- if ( 2 == $question['comments'] ) { ?>
936
- <textarea class="qsm-question-comment qsm-question-comment-large mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" ></textarea>";
937
- <?php }
938
- // Checks if a hint is entered.
939
- if ( ! empty( $question['hints'] ) ) {
940
- echo '<div class="qsm-hint qsm_hint mlw_qmn_hint_link qsm_tooltip">' . wp_kses_post( $options->hint_text ) . '<span class="qsm_tooltiptext">' . wp_kses_post( $question['hints'] ) . '</span></div>';
941
- }
942
- ?>
943
- </div>
944
  <?php
945
  }
946
- if ( $enable_pagination_quiz ) {
947
  ?>
948
- <span class="pages_count">
949
  <?php
950
- $text_c = $pages_count . __( ' out of ', 'quiz-master-next' ) . $total_pages_count;
951
- echo apply_filters( 'qsm_total_pages_count', $text_c, $pages_count, $total_pages_count );
952
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
953
  </span>
954
- <?php } ?>
955
  </section>
956
  <?php
957
  $pages_count++;
@@ -962,28 +1028,27 @@ class QMNQuizManager {
962
  ?>
963
  <section class="qsm-page">
964
  <div class="quiz_section quiz_begin">
965
- <label for='mlwQuizComments'
966
- class='qsm-comments-label mlw_qmn_comment_section_text'><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data ); ?></label>
967
- <textarea id='mlwQuizComments' name='mlwQuizComments' class='qsm-comments qmn_comment_section'></textarea>
968
  </div>
969
  </section>
970
  <?php
971
  }
972
- if ( count( $pages ) > 1 && ( ! empty( $options->message_end_template ) || ( 1 == $options->contact_info_location && $contact_fields ) ) ) {
973
- $message_after = wpautop( htmlspecialchars_decode( $options->message_end_template, ENT_QUOTES ) );
974
- ?>
975
  <section class="qsm-page" style="display: none;">
976
  <div class="quiz_section">
977
  <div class='qsm-after-message mlw_qmn_message_end'><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data ); ?></div>
978
  <?php
979
- if ( 1 == $options->contact_info_location ) {
980
- echo QSM_Contact_Manager::display_fields( $options );
981
- }
982
- ?>
983
  </div>
984
  <?php
985
- // Legacy code.
986
- do_action( 'mlw_qmn_end_quiz_section' );
987
  ?>
988
  </section>
989
  <?php
@@ -994,8 +1059,10 @@ class QMNQuizManager {
994
  *
995
  * @since 7.3.5
996
  */
997
- add_action( 'wp_footer', function () use ( $options ) {
998
- ?>
 
 
999
  <!-- View for pagination -->
1000
  <script type="text/template" id="tmpl-qsm-pagination-<?php echo esc_attr( $options->quiz_id ); ?>">
1001
  <div class="qsm-pagination qmn_pagination border margin-bottom">
@@ -1007,8 +1074,9 @@ class QMNQuizManager {
1007
  <input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value='<?php echo esc_attr( $options->submit_button_text ); ?>' />
1008
  </div>
1009
  </script>
1010
- <?php
1011
- });
 
1012
  ?>
1013
  <input type="hidden" name="qmn_question_list" value="<?php echo esc_attr( $question_list ); ?>" />
1014
  <?php
@@ -1019,10 +1087,10 @@ class QMNQuizManager {
1019
  *
1020
  * Generates the content for the beginning section of the quiz page
1021
  *
1022
- * @since 4.0.0
1023
- * @param array $qmn_quiz_options The database row of the quiz.
1024
- * @param array $qmn_array_for_variables The array of results for the quiz.
1025
- * @return string The content for the beginning section
1026
  * @deprecated 5.2.0 Use new page system instead
1027
  */
1028
  public function display_begin_section( $qmn_quiz_options, $qmn_array_for_variables ) {
@@ -1033,18 +1101,26 @@ class QMNQuizManager {
1033
  global $mlw_qmn_section_count;
1034
  $mlw_qmn_section_count += 1;
1035
  $animation_effect = isset( $qmn_quiz_options->quiz_animation ) && '' !== $qmn_quiz_options->quiz_animation ? ' animated ' . $qmn_quiz_options->quiz_animation : '';
1036
- ?><div class="qsm-auto-page-row quiz_section <?php echo esc_attr( $animation_effect ); ?> quiz_begin"><?php
1037
- $message_before = wpautop( htmlspecialchars_decode( $qmn_quiz_options->message_before, ENT_QUOTES ) );
1038
- $message_before = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_before, $qmn_array_for_variables );
1039
- $editor_text = $wp_embed->run_shortcode( $message_before );
1040
- $editor_text = preg_replace( '/\s*[\w\/:\.]*youtube.com\/watch\?v=([\w]+)([\w\*\-\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $editor_text );
1041
- ?><div class='mlw_qmn_message_before'><?php
1042
- echo do_shortcode( wp_kses_post( $editor_text ) ) ;
1043
- ?></div><?php
1044
- if ( 0 == $qmn_quiz_options->contact_info_location ) {
1045
- echo QSM_Contact_Manager::display_fields( $qmn_quiz_options );
1046
- }
1047
- ?></div><?php
 
 
 
 
 
 
 
 
1048
  } else {
1049
  $qmn_json_data['first_page'] = false;
1050
  }
@@ -1055,12 +1131,12 @@ class QMNQuizManager {
1055
  *
1056
  * Generates the content for the questions part of the quiz page
1057
  *
1058
- * @since 4.0.0
1059
- * @param array $qmn_quiz_options The database row of the quiz.
1060
- * @param array $qmn_quiz_questions The questions of the quiz.
1061
- * @param array $qmn_quiz_answers The answers of the quiz.
1062
- * @uses QMNPluginHelper:display_question() Displays a question
1063
- * @return string The content for the questions section
1064
  * @deprecated 5.2.0 Use new page system instead
1065
  */
1066
  public function display_questions( $qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers ) {
@@ -1080,19 +1156,23 @@ class QMNQuizManager {
1080
  foreach ( $qmn_quiz_questions as $mlw_question ) {
1081
  if ( 0 != $pagination_optoin ) {
1082
  if ( 1 == $pagination_optoin ) {
1083
- ?><div class="qsm-auto-page-row qsm-apc-<?php echo esc_attr( $current_page_number ); ?>" style="display: none;"><?php
 
 
1084
  $current_page_number++;
1085
  } else {
1086
  if ( 1 == $pages_count % $pagination_optoin || 1 == $pages_count ) { // beginning of the row or first.
1087
- ?><div class="qsm-auto-page-row qsm-apc-<?php echo esc_attr( $current_page_number ); ?>" style="display: none;"><?php
 
 
1088
  $current_page_number++;
1089
  }
1090
  }
1091
  echo apply_filters( 'qsm_auto_page_begin_row', '', ( $current_page_number - 1 ), $qmn_quiz_options, $qmn_quiz_questions );
1092
  }
1093
- $category_class = '';
1094
- $multicategories = QSM_Questions::get_question_categories($mlw_question->question_id);
1095
- $question_categories = isset($multicategories['category_tree']) && ! empty($multicategories['category_tree'] ) ? array_keys($multicategories['category_name']) : array();
1096
  if ( ! empty( $question_categories ) ) {
1097
  foreach ( $question_categories as $cat ) {
1098
  $category_class .= ' category-section-id-c' . esc_attr( $cat );
@@ -1100,36 +1180,52 @@ class QMNQuizManager {
1100
  }
1101
 
1102
  $question_id_list .= $mlw_question->question_id . 'Q';
1103
- ?><div class="quiz_section qsm-question-wrapper <?php echo esc_attr($animation_effect); ?> question-section-id-<?php echo esc_attr( $mlw_question->question_id ); ?> slide<?php echo esc_attr( $mlw_qmn_section_count.' '.$category_class ); ?>"><?php
 
 
1104
  $mlwQuizMasterNext->pluginHelper->display_question( $mlw_question->question_type_new, $mlw_question->question_id, $qmn_quiz_options );
1105
-
1106
  if ( 0 == $mlw_question->comments ) {
1107
- ?><input type="text" class="mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" name="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" placeholder="<?php echo esc_attr( $qmn_quiz_options->comment_field_text ); ?>" onclick="qmnClearField(this)" /><br /><?php
 
 
1108
  }
1109
  if ( 2 == $mlw_question->comments ) {
1110
- ?><textarea cols="70" rows="5" class="mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" name="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" placeholder="<?php echo esc_attr( $qmn_quiz_options->comment_field_text ); ?>" onclick="qmnClearField(this)"></textarea><br /><?php
 
 
1111
  }
1112
-
1113
  // Checks if a hint is entered.
1114
  if ( ! empty( $mlw_question->hints ) ) {
1115
- ?><div class="qsm-hint qsm_hint mlw_qmn_hint_link qsm_tooltip"><?php echo esc_html( $qmn_quiz_options->hint_text ); ?><span class="qsm_tooltiptext"><?php echo wp_kses( preg_replace( '#<script(.*?)>(.*?)</script>#is', '', htmlspecialchars_decode( $mlw_question->hints, ENT_QUOTES ) ), wp_kses_allowed_html( 'post' ) ); ?></span></div><br /><br /><?php
 
 
1116
  }
1117
- ?></div><!-- .quiz_section --><?php
 
 
1118
  if ( 0 == $pagination_optoin ) {
1119
 
1120
  } elseif ( 1 == $pagination_optoin || 0 == $pages_count % $pagination_optoin || count( $qmn_quiz_questions ) == $pages_count ) { // end of the row or last
1121
- ?></div><!-- .qsm-auto-page-row --><?php
 
 
1122
  }
1123
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1124
  $pages_count++;
1125
  }
1126
  if ( $enable_pagination_quiz ) {
1127
- ?><span class="pages_count" style="display: none;"><?php
1128
- $text_c = $current_page_number . __( ' out of ', 'quiz-master-next' ) . $total_pagination;
1129
- echo apply_filters( 'qsm_total_pages_count', $text_c, $pages_count, $total_pages_count );
1130
- ?></span><?php
 
 
 
 
1131
  }
1132
- ?><input type="hidden" name="qmn_question_list" value="<?php echo esc_attr( $question_id_list ); ?>" /><?php
 
 
1133
  }
1134
 
1135
  /**
@@ -1137,25 +1233,27 @@ class QMNQuizManager {
1137
  *
1138
  * Generates the content for the comment section part of the quiz page
1139
  *
1140
- * @since 4.0.0
1141
- * @param array $qmn_quiz_options The database row of the quiz.
1142
- * @param array $qmn_array_for_variables The array of results for the quiz.
1143
- * @return string The content for the comment section
1144
  * @deprecated 5.2.0 Use new page system instead
1145
  */
1146
  public function display_comment_section( $qmn_quiz_options, $qmn_array_for_variables ) {
1147
  global $mlw_qmn_section_count;
1148
  if ( 0 == $qmn_quiz_options->comment_section ) {
1149
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1150
- $qsm_d_none = 0 == $qmn_quiz_options->randomness_order ? 'qsm-d-none' : '';
1151
  ?>
1152
- <div class="quiz_section quiz_end qsm-auto-page-row qsm-quiz-comment-section slide <?php echo esc_attr( $mlw_qmn_section_count.' '.$qsm_d_none ); ?>" >
1153
  <?php
1154
- $message_comments = wpautop( htmlspecialchars_decode( $qmn_quiz_options->message_comment, ENT_QUOTES ) );
1155
- $message_comments = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $qmn_array_for_variables );
1156
- ?><label for="mlwQuizComments" class="mlw_qmn_comment_section_text"><?php echo wp_kses( $message_comments, wp_kses_allowed_html( 'post' ) ); ?></label><br />
 
1157
  <textarea cols="60" rows="10" id="mlwQuizComments" name="mlwQuizComments" class="qmn_comment_section"></textarea>
1158
- </div><?php
 
1159
  }
1160
  }
1161
 
@@ -1164,15 +1262,15 @@ class QMNQuizManager {
1164
  *
1165
  * Generates the content for the end section of the quiz page
1166
  *
1167
- * @since 4.0.0
1168
- * @param array $qmn_quiz_options The database row of the quiz.
1169
- * @param array $qmn_array_for_variables The array of results for the quiz.
1170
- * @return string The content for the end section
1171
  * @deprecated 5.2.0 Use new page system instead
1172
  */
1173
  public function display_end_section( $qmn_quiz_options, $qmn_array_for_variables ) {
1174
  global $mlw_qmn_section_count;
1175
- $section_display = '';
1176
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1177
  $pagination_optoin = $qmn_quiz_options->pagination;
1178
  // Legacy Code.
@@ -1189,15 +1287,21 @@ class QMNQuizManager {
1189
  do_action( 'mlw_qmn_end_quiz_section' );
1190
  $qsm_d_none = 0 == $qmn_quiz_options->randomness_order ? 'qsm-d-none' : '';
1191
  if ( ! empty( $section_display ) ) {
1192
- ?><br />
1193
- <div class="qsm-auto-page-row quiz_section quiz_end <?php echo esc_attr( $qsm_d_none ); ?>"><?php
1194
- echo wp_kses( $section_display, wp_kses_allowed_html( 'post' ) );
1195
- ?><input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value="<?php echo esc_attr( $qmn_quiz_options->submit_button_text ); ?>" />
1196
- </div><?php
 
 
 
 
1197
  } else {
1198
- ?><div class="qsm-auto-page-row quiz_section quiz_end empty_quiz_end <?php echo esc_attr( $qsm_d_none ); ?>" >
 
1199
  <input type="submit" class="qsm-btn qsm-submit-btn qmn_btn" value="<?php echo esc_attr( $qmn_quiz_options->submit_button_text ); ?>" />
1200
- </div><?php
 
1201
  }
1202
  }
1203
 
@@ -1206,10 +1310,10 @@ class QMNQuizManager {
1206
  *
1207
  * Generates the content for the results page part of the shortcode
1208
  *
1209
- * @since 4.0.0
1210
- * @param array $options The database row of the quiz.
1211
- * @param array $data The array of results for the quiz.
1212
- * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
1213
  * @return string The content for the results page section
1214
  */
1215
  public function display_results( $options, $data ) {
@@ -1221,8 +1325,8 @@ class QMNQuizManager {
1221
  /**
1222
  * Calls the results page from ajax
1223
  *
1224
- * @since 4.6.0
1225
- * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
1226
  * @return string The content for the results page section
1227
  */
1228
  public function ajax_submit_results() {
@@ -1232,12 +1336,12 @@ class QMNQuizManager {
1232
  $qmn_allowed_visit = true;
1233
  $quiz = isset( $_POST['qmn_quiz_id'] ) ? intval( $_POST['qmn_quiz_id'] ) : '';
1234
  $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
1235
- $options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
1236
  $qsm_option = isset( $options->quiz_settings ) ? maybe_unserialize( $options->quiz_settings ) : array();
1237
  $qsm_option = array_map( 'maybe_unserialize', $qsm_option );
1238
- $dateStr = $qsm_option['quiz_options']['scheduled_time_end'];
1239
- $timezone = isset( $_POST['currentuserTimeZone'] ) ? sanitize_text_field( wp_unslash( $_POST['currentuserTimeZone'] ) ) : '';
1240
- $dtUtcDate = strtotime($dateStr. ' '. $timezone);
1241
 
1242
  if ( '1' === $qsm_option['quiz_options']['not_allow_after_expired_time'] && isset( $_POST['currentuserTime'] ) && sanitize_text_field( wp_unslash( $_POST['currentuserTime'] ) ) > $dtUtcDate ) {
1243
  echo wp_json_encode( array( 'quizExpired' => true ) );
@@ -1286,15 +1390,15 @@ class QMNQuizManager {
1286
  *
1287
  * Prepares and save the results, prepares and send emails, prepare results page
1288
  *
1289
- * @since 4.6.0
1290
- * @param array $qmn_quiz_options The database row of the quiz.
1291
- * @param array $qmn_array_for_variables The array of results for the quiz.
1292
- * @uses QMNQuizManager:check_answers() Creates display for beginning section
1293
- * @uses QMNQuizManager:check_comment_section() Creates display for questions
1294
- * @uses QMNQuizManager:display_results_text() Creates display for end section
1295
- * @uses QMNQuizManager:display_social() Creates display for comment section
1296
- * @uses QMNQuizManager:send_user_email() Creates display for end section
1297
- * @uses QMNQuizManager:send_admin_email() Creates display for end section
1298
  * @return string The content for the results page section
1299
  */
1300
  public function submit_results( $qmn_quiz_options, $qmn_array_for_variables ) {
@@ -1343,18 +1447,18 @@ class QMNQuizManager {
1343
  }
1344
  }
1345
 
1346
- $mlw_qmn_pagetime = isset( $_POST['pagetime'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['pagetime'] ) ) : array();
1347
- $mlw_qmn_timer = isset( $_POST['timer'] ) ? intval( $_POST['timer'] ) : 0;
1348
- $mlw_qmn_timer_ms = isset( $_POST['timer_ms'] ) ? intval( $_POST['timer_ms'] ) : 0;
1349
- $qmn_array_for_variables['user_id'] = get_current_user_id();
1350
- $qmn_array_for_variables['timer'] = $mlw_qmn_timer;
1351
- $qmn_array_for_variables['timer_ms'] = $mlw_qmn_timer_ms;
1352
- $qmn_array_for_variables['time_taken'] = current_time( 'h:i:s A m/d/Y' );
1353
- $qmn_array_for_variables['contact'] = $contact_responses;
1354
- $hidden_questions = array();
1355
  if ( isset( $_POST['qsm_hidden_questions'] ) ) {
1356
- $hidden_questions = sanitize_text_field( wp_unslash( $_POST['qsm_hidden_questions'] ) );
1357
- $hidden_questions = json_decode( $hidden_questions, true );
1358
  }
1359
  $qmn_array_for_variables['hidden_questions'] = $hidden_questions;
1360
  $qmn_array_for_variables = apply_filters( 'qsm_result_variables', $qmn_array_for_variables );
@@ -1365,8 +1469,8 @@ class QMNQuizManager {
1365
  $result_display = apply_filters( 'qmn_after_check_answers', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
1366
  $qmn_array_for_variables['comments'] = $this->check_comment_section( $qmn_quiz_options, $qmn_array_for_variables );
1367
  $result_display = apply_filters( 'qmn_after_check_comments', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
1368
- $unique_id = uniqid();
1369
- $results_id = 0;
1370
  // If the store responses in database option is set to Yes.
1371
  if ( 0 != $qmn_quiz_options->store_responses ) {
1372
  // Creates our results array.
@@ -1405,6 +1509,7 @@ class QMNQuizManager {
1405
  array( 'result_id' => $results_id )
1406
  );
1407
  } else {
 
1408
  $results_insert = $wpdb->insert(
1409
  $table_name,
1410
  array(
@@ -1427,6 +1532,8 @@ class QMNQuizManager {
1427
  'deleted' => 0,
1428
  'unique_id' => $unique_id,
1429
  'form_type' => isset( $qmn_quiz_options->form_type ) ? $qmn_quiz_options->form_type : 0,
 
 
1430
  ),
1431
  array(
1432
  '%d',
@@ -1448,18 +1555,20 @@ class QMNQuizManager {
1448
  '%d',
1449
  '%s',
1450
  '%d',
 
 
1451
  )
1452
  );
1453
  $results_id = $wpdb->insert_id;
1454
  }
1455
  }
1456
- $qmn_array_for_variables['response_saved'] = isset($results_insert) ? $results_insert : false;
1457
- $qmn_array_for_variables['result_id'] = $results_id;
1458
  $qmn_array_for_variables['result_unique_id'] = $unique_id;
1459
 
1460
  // Converts date to the preferred format
1461
  global $mlwQuizMasterNext;
1462
- $qmn_array_for_variables = $mlwQuizMasterNext->pluginHelper->convert_to_preferred_date_format($qmn_array_for_variables);
1463
 
1464
  // Determines redirect/results page.
1465
  $results_pages = $this->display_results_text( $qmn_quiz_options, $qmn_array_for_variables );
@@ -1469,17 +1578,16 @@ class QMNQuizManager {
1469
  $result_display .= $this->display_social( $qmn_quiz_options, $qmn_array_for_variables );
1470
  $result_display = apply_filters( 'qmn_after_social_media', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
1471
  if ( 1 == $qmn_quiz_options->enable_retake_quiz_button ) {
1472
-
1473
  $result_display .= '<form method="POST">';
1474
  $result_display .= '<input type="hidden" value="' . $qmn_array_for_variables['quiz_id'] . '" name="qsm_retake_quiz_id" />';
1475
- $result_display .= '<input type="submit" value="' . apply_filters( 'qsm_retake_quiz_text', __( 'Retake Quiz', 'quiz-master-next' ) ). '" name="qsm_retake_button" />';
1476
  $result_display .= '</form>';
1477
  }
1478
 
1479
  /*
1480
- * Update the option `qmn_quiz_taken_cnt` value by 1 each time
1481
- * whenever the record inserted into the required table.
1482
- */
1483
  if ( $results_insert ) {
1484
  $rec_inserted = intval( get_option( 'qmn_quiz_taken_cnt' ) );
1485
  if ( 1000 > $rec_inserted ) {
@@ -1553,10 +1661,10 @@ class QMNQuizManager {
1553
  *
1554
  * Calculates the users scores for the quiz
1555
  *
1556
- * @since 4.0.0
1557
- * @param array $options The database row of the quiz
1558
- * @param array $quiz_data The array of results for the quiz
1559
- * @uses QMNPluginHelper:display_review() Scores the question
1560
  * @return array The results of the user's score
1561
  */
1562
  public static function check_answers( $options, $quiz_data ) {
@@ -1576,16 +1684,16 @@ class QMNQuizManager {
1576
  }
1577
 
1578
  // Prepare variables
1579
- $points_earned = 0;
1580
- $total_correct = 0;
1581
- $total_score = 0;
1582
- $user_answer = '';
1583
- $correct_answer = '';
1584
- $correct_status = 'incorrect';
1585
- $answer_points = 0;
1586
- $question_data = array();
1587
- $total_possible_points = 0;
1588
- $attempted_question = 0;
1589
  $minimum_possible_points = 0;
1590
  // Question types to calculate result on
1591
  $result_question_types = array(
@@ -1602,6 +1710,9 @@ class QMNQuizManager {
1602
  13, // Polar.
1603
  );
1604
 
 
 
 
1605
  // If deprecated pagination setting is not used, use new system...
1606
  if ( 0 == $options->question_from_total && 0 !== count( $pages ) ) {
1607
  // Cycle through each page in quiz.
@@ -1612,21 +1723,21 @@ class QMNQuizManager {
1612
  foreach ( $question_list as $question_id ) {
1613
  // When the questions are the same...
1614
  if ( $page_question_id == $question_id ) {
1615
- $question = $questions[ $page_question_id ];
1616
- $question_type_new = $question['question_type_new'];
1617
- // Ignore non points questions from result
1618
- $hidden_questions = is_array( $quiz_data['hidden_questions'] ) ? $quiz_data['hidden_questions'] : array();
1619
 
1620
- // Reset question-specific variables
1621
  $user_answer = '';
1622
  $correct_answer = '';
1623
  $correct_status = 'incorrect';
1624
  $answer_points = 0;
1625
 
1626
- // Get maximum and minimum points for the quiz
1627
  if ( ! in_array( intval( $question_id ), $hidden_questions, true ) ) {
1628
- $max_min_result = QMNQuizManager::qsm_max_min_points($options,$question);
1629
- $total_possible_points += $max_min_result['max_point'];
1630
  $minimum_possible_points += $max_min_result['min_point'];
1631
  }
1632
 
@@ -1701,23 +1812,23 @@ class QMNQuizManager {
1701
  // Cycle through each page in quiz.
1702
  foreach ( $questions as $question ) {
1703
 
1704
- // Cycle through each question that appeared to the user
1705
  foreach ( $question_list as $question_id ) {
1706
 
1707
  // When the questions are the same...
1708
  if ( $question['question_id'] == $question_id ) {
1709
- // Reset question-specific variables
1710
  $user_answer = '';
1711
  $correct_answer = '';
1712
  $correct_status = 'incorrect';
1713
  $answer_points = 0;
1714
 
1715
- // Get maximum and minimum points for the quiz
1716
- $max_min_result = QMNQuizManager::qsm_max_min_points($options,$question);
1717
- $total_possible_points += $max_min_result['max_point'];
1718
  $minimum_possible_points += $max_min_result['min_point'];
1719
 
1720
- // Send question to our grading function
1721
  $results_array = apply_filters( 'qmn_results_array', $mlwQuizMasterNext->pluginHelper->display_review( $question['question_type_new'], $question['question_id'] ), $question );
1722
 
1723
  // If question was graded correctly.
@@ -1725,7 +1836,7 @@ class QMNQuizManager {
1725
  $points_earned += $results_array['points'];
1726
  $answer_points += $results_array['points'];
1727
 
1728
- // If the user's answer was correct
1729
  if ( 'correct' == $results_array['correct'] ) {
1730
  $total_correct += 1;
1731
  $correct_status = 'correct';
@@ -1738,7 +1849,7 @@ class QMNQuizManager {
1738
  $attempted_question++;
1739
  }
1740
  }
1741
- // If a comment was submitted
1742
  if ( isset( $_POST[ 'mlwComment' . $question['question_id'] ] ) ) {
1743
  $comment = htmlspecialchars( sanitize_textarea_field( wp_unslash( $_POST[ 'mlwComment' . $question['question_id'] ] ) ), ENT_QUOTES );
1744
  } else {
@@ -1778,7 +1889,6 @@ class QMNQuizManager {
1778
  }
1779
  }
1780
 
1781
-
1782
  // Calculate Total Percent Score And Average Points Only If Total Questions Doesn't Equal Zero To Avoid Division By Zero Error
1783
  if ( 0 !== $total_questions ) {
1784
  $total_score = round( ( ( $total_correct / $total_questions ) * 100 ), 2 );
@@ -1789,13 +1899,13 @@ class QMNQuizManager {
1789
  // Get random order
1790
  $qsm_random_que_ids = get_option( 'qsm_random_que_ids' );
1791
  if ( ! empty( $qsm_random_que_ids ) && is_array( $qsm_random_que_ids ) ) {
1792
- $qs_ids = array_column( $question_data, 'id' );
1793
  $has_diff = array_diff( $qs_ids, $qsm_random_que_ids );
1794
  // Check random option value has all the questions in previous order
1795
  if ( empty( $has_diff ) ) {
1796
- $new_question_data = [];
1797
  foreach ( $qsm_random_que_ids as $que_id ) {
1798
- $key = array_search( $que_id, $qs_ids, true );
1799
  $new_question_data[] = $question_data[ $key ];
1800
  }
1801
  if ( ! empty( $new_question_data ) ) {
@@ -1807,17 +1917,22 @@ class QMNQuizManager {
1807
  }
1808
 
1809
  // Return array to be merged with main user response array
1810
- return apply_filters('qsm_check_answers_results' , array(
1811
- 'total_points' => $points_earned,
1812
- 'total_score' => $total_score,
1813
- 'total_correct' => $total_correct,
1814
- 'total_questions' => $total_questions,
1815
- 'question_answers_display' => '', // Kept for backwards compatibility
1816
- 'question_answers_array' => $question_data,
1817
- 'total_possible_points' => $total_possible_points,
1818
- 'total_attempted_questions' => $attempted_question,
1819
- 'minimum_possible_points' => $minimum_possible_points,
1820
- ), $options, $quiz_data );
 
 
 
 
 
1821
  }
1822
 
1823
  /**
@@ -1825,9 +1940,9 @@ class QMNQuizManager {
1825
  *
1826
  * Checks to see if the user left a comment and returns the comment
1827
  *
1828
- * @since 4.0.0
1829
- * @param array $qmn_quiz_options The database row of the quiz
1830
- * @param array $qmn_array_for_variables The array of results for the quiz
1831
  * @return string The user's comments
1832
  */
1833
  public function check_comment_section( $qmn_quiz_options, $qmn_array_for_variables ) {
@@ -1841,104 +1956,104 @@ class QMNQuizManager {
1841
  /**
1842
  * computes maximum and minimum points for a quiz
1843
  *
1844
- * @since 7.3.5
1845
- * @param array $options
1846
- * @param array $question
1847
  * @return string $max_min_result
1848
  */
1849
- public static function qsm_max_min_points( $options , $question ) {
1850
 
1851
  $max_value_array = array();
1852
  $min_value_array = array();
1853
 
1854
- $valid_grading_system = (1 == $options->system || 3 == $options->system );
1855
- $valid_answer_array = (isset($question['answers']) && ! empty($question['answers']));
1856
 
1857
  $max_min_result = array(
1858
  'max_point' => 0,
1859
  'min_point' => 0,
1860
  );
1861
 
1862
- if ( ! ($valid_answer_array && $valid_grading_system) ) {
1863
- return $max_min_result;
1864
  }
1865
 
1866
  foreach ( $question['answers'] as $single_answerk_key => $single_answer_arr ) {
1867
- if ( isset($single_answer_arr[1]) ) {
1868
- $single_answer_arr[1] = apply_filters('qsm_single_answer_arr', $single_answer_arr[1]);
1869
- if ( intval($single_answer_arr[1]) > 0 ) {
1870
- array_push($max_value_array, $single_answer_arr[1]);
1871
- }
1872
- if ( intval($single_answer_arr[1]) < 0 ) {
1873
- array_push($min_value_array, $single_answer_arr[1]);
 
1874
  }
1875
  }
1876
- }
1877
 
1878
- $question_type = $question['question_type_new'];
1879
- $question_required = ( 0 === maybe_unserialize($question['question_settings'])['required']);
1880
- $multi_response = ( "4" === $question_type || "10" === $question_type ) ;
1881
 
1882
- return QMNQuizManager::qsm_max_min_points_conditions( $max_value_array, $min_value_array, $question_required, $multi_response);
1883
 
1884
  }
1885
  /**
1886
  * evaluates conditions and returns maximum and minimum points for a quiz
1887
  *
1888
- * @since 7.3.5
1889
- * @param array $max_value_array
1890
- * @param array $min_value_array
1891
- * @param array $question_required
1892
- * @param array $multi_response
1893
  * @return string $max_min_result
1894
  */
1895
- public static function qsm_max_min_points_conditions( $max_value_array, $min_value_array, $question_required, $multi_response ) {
1896
  $max_min_result = array(
1897
  'max_point' => 0,
1898
  'min_point' => 0,
1899
  );
1900
- if ( empty($max_value_array) && empty($min_value_array) ) {
1901
- return $max_min_result;
1902
  }
1903
- if ( empty($max_value_array) && $question_required && $multi_response ) {
1904
- $max_min_result['max_point'] = max($min_value_array);
1905
- $max_min_result['min_point'] = array_sum($min_value_array);
1906
  }
1907
- if ( empty($max_value_array) && $question_required && ! $multi_response ) {
1908
- $max_min_result['max_point'] = max($min_value_array);
1909
- $max_min_result['min_point'] = min($min_value_array);
1910
  }
1911
- if ( empty($max_value_array) && ! $question_required && $multi_response ) {
1912
- $max_min_result['max_point'] = 0;
1913
- $max_min_result['min_point'] = array_sum($min_value_array);
1914
  }
1915
- if ( empty($max_value_array) && ! $question_required && ! $multi_response ) {
1916
- $max_min_result['max_point'] = 0;
1917
- $max_min_result['min_point'] = min($min_value_array);
1918
  }
1919
- if ( empty($min_value_array) && $question_required && $multi_response ) {
1920
- $max_min_result['min_point'] = min($max_value_array);
1921
- $max_min_result['max_point'] = array_sum($max_value_array);
1922
  }
1923
- if ( empty($min_value_array) && $question_required && ! $multi_response ) {
1924
- $max_min_result['min_point'] = min($max_value_array);
1925
- $max_min_result['max_point'] = max($max_value_array);
1926
  }
1927
- if ( empty($min_value_array) && ! $question_required && $multi_response ) {
1928
- $max_min_result['min_point'] = 0;
1929
- $max_min_result['max_point'] = array_sum($max_value_array);
1930
  }
1931
- if ( empty($min_value_array) && ! $question_required && ! $multi_response ) {
1932
- $max_min_result['min_point'] = 0;
1933
- $max_min_result['max_point'] = max($max_value_array);
1934
  }
1935
- if ( ! empty($max_value_array) && ! empty($min_value_array) && $multi_response ) {
1936
- $max_min_result['max_point'] = array_sum($max_value_array);
1937
- $max_min_result['min_point'] = array_sum($min_value_array);
1938
  }
1939
- if ( ! empty($max_value_array) && ! empty($min_value_array) && ! $multi_response ) {
1940
- $max_min_result['max_point'] = max($max_value_array);
1941
- $max_min_result['min_point'] = min($min_value_array);
1942
  }
1943
  return $max_min_result;
1944
  }
@@ -1946,11 +2061,11 @@ class QMNQuizManager {
1946
  /**
1947
  * Displays Results Text
1948
  *
1949
- * @since 4.0.0
1950
  * @deprecated 6.1.0 Use the newer results page class instead.
1951
- * @param array $options The quiz settings.
1952
- * @param array $response_data The array of results for the quiz.
1953
- * @return string The contents for the results text
1954
  */
1955
  public function display_results_text( $options, $response_data ) {
1956
  return QSM_Results_Pages::generate_pages( $response_data );
@@ -1960,10 +2075,10 @@ class QMNQuizManager {
1960
  * Displays social media buttons
1961
  *
1962
  * @deprecated 6.1.0 Use the social media template variables instead.
1963
- * @since 4.0.0
1964
- * @param array $qmn_quiz_options The database row of the quiz.
1965
- * @param array $qmn_array_for_variables The array of results for the quiz.
1966
- * @return string The content of the social media button section
1967
  */
1968
  public function display_social( $qmn_quiz_options, $qmn_array_for_variables ) {
1969
  $social_display = '';
@@ -1995,9 +2110,9 @@ class QMNQuizManager {
1995
  * Prepares the email to the user and then sends the email
1996
  *
1997
  * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
1998
- * @since 4.0.0
1999
- * @param array $qmn_quiz_options The database row of the quiz
2000
- * @param array $qmn_array_for_variables The array of results for the quiz
2001
  */
2002
  public function send_user_email( $qmn_quiz_options, $qmn_array_for_variables ) {
2003
  add_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
@@ -2100,9 +2215,9 @@ class QMNQuizManager {
2100
  * Prepares the email to the admin and then sends the email
2101
  *
2102
  * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
2103
- * @since 4.0.0
2104
- * @param array $qmn_quiz_options The database row of the quiz
2105
- * @param arrar $qmn_array_for_variables The array of results for the quiz
2106
  */
2107
  public function send_admin_email( $qmn_quiz_options, $qmn_array_for_variables ) {
2108
  // Switch email type to HTML
@@ -2128,8 +2243,8 @@ class QMNQuizManager {
2128
  }
2129
  }
2130
 
2131
- $mlw_message = '';
2132
- $mlw_subject = '';
2133
  $mlw_admin_email_array = maybe_unserialize( $qmn_quiz_options->admin_email_template );
2134
  if ( is_array( $mlw_admin_email_array ) ) {
2135
  // Cycle through landing pages
@@ -2207,7 +2322,7 @@ class QMNQuizManager {
2207
  /**
2208
  * Returns the quiz taker's IP if IP collection is enabled
2209
  *
2210
- * @since 5.3.0
2211
  * @return string The IP address or a phrase if not collected
2212
  */
2213
  private function get_user_ip() {
@@ -2249,7 +2364,7 @@ class QMNQuizManager {
2249
  *
2250
  * @since 6.4.11
2251
  *
2252
- * @param string $plugin Path to the plugin file relative to the plugins directory.
2253
  * @return bool True, if in the active plugins list. False, not in the list.
2254
  */
2255
  private function qsm_plugin_active( $plugin ) {
@@ -2261,7 +2376,7 @@ class QMNQuizManager {
2261
  *
2262
  * @since 6.4.11
2263
  *
2264
- * @param string $plugin Path to the plugin file relative to the plugins directory.
2265
  * @return bool True if active for the network, otherwise false.
2266
  */
2267
  private function qsm_plugin_active_for_network() {
@@ -2283,7 +2398,7 @@ class QMNQuizManager {
2283
  * @singce 7.0
2284
  */
2285
  public function qsm_process_background_email() {
2286
- require_once plugin_dir_path( __FILE__ ) . 'class-qmn-background-process.php';
2287
  $this->qsm_background_email = new QSM_Background_Request();
2288
  }
2289
 
@@ -2293,37 +2408,37 @@ class QMNQuizManager {
2293
  * @since 7.1.2
2294
  *
2295
  * @global obj $wpdb
2296
- * @param url $attachment_url
2297
  * @return int
2298
  */
2299
  public function qsm_get_attachment_id_from_url( $attachment_url = '' ) {
2300
 
2301
- global $wpdb;
2302
- $attachment_id = false;
2303
 
2304
- // If there is no url, return.
2305
  if ( '' == $attachment_url ) {
2306
- return;
2307
  }
2308
 
2309
- // Get the upload directory paths
2310
- $upload_dir_paths = wp_upload_dir();
2311
 
2312
- // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
2313
  if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) {
2314
 
2315
- // If this is the URL of an auto-generated thumbnail, get the URL of the original image
2316
- $attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url );
2317
 
2318
- // Remove the upload path base directory from the attachment URL
2319
- $attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url );
2320
 
2321
- // Finally, run a custom database query to get the attachment ID from the modified attachment URL
2322
- $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 ) );
2323
 
2324
  }
2325
 
2326
- return $attachment_id;
2327
  }
2328
  }
2329
 
@@ -2356,9 +2471,9 @@ add_filter( 'qmn_begin_shortcode', 'qsm_scheduled_timeframe_check', 99, 3 );
2356
  * @since 7.0.0 Added the condition for start time ( end time blank ) and end time ( start time blank ).
2357
  *
2358
  * @global boolean $qmn_allowed_visit
2359
- * @param HTML $display
2360
- * @param Object $options
2361
- * @param Array $variable_data
2362
  * @return HTML This function check the time frame of quiz.
2363
  */
2364
  function qsm_scheduled_timeframe_check( $display, $options, $variable_data ) {
@@ -2407,14 +2522,13 @@ add_filter( 'qmn_begin_shortcode', 'qmn_total_user_tries_check', 10, 3 );
2407
  /**
2408
  * Checks if user has already reach the user limit of the quiz
2409
  *
2410
- * @since 5.0.0
2411
- * @param string $display The HTML displayed for the quiz
2412
- * @param array $qmn_quiz_options The settings for the quiz
2413
- * @param array $qmn_array_for_variables The array of data by the quiz
2414
  * @return string The altered HTML display for the quiz
2415
  */
2416
  function qmn_total_user_tries_check( $display, $qmn_quiz_options, $qmn_array_for_variables ) {
2417
-
2418
  global $qmn_allowed_visit;
2419
  if ( 0 != $qmn_quiz_options->total_user_tries ) {
2420
 
@@ -2537,7 +2651,7 @@ function qmn_update_taken( $display, $qmn_quiz_options, $qmn_array_for_variables
2537
  return $display;
2538
  }
2539
 
2540
- //This function helps set the email type to HTML
2541
 
2542
  function mlw_qmn_set_html_content_type() {
2543
  return 'text/html';
@@ -2546,7 +2660,9 @@ function mlw_qmn_set_html_content_type() {
2546
  function qsm_time_in_milliseconds() {
2547
  return round( microtime( true ) * 1000 );
2548
  }
2549
- add_filter('wp_video_extensions', function( $exts ) {
 
 
2550
  $exts[] = 'mov';
2551
  $exts[] = 'avi';
2552
  $exts[] = 'wmv';
15
  */
16
  class QMNQuizManager {
17
 
18
+
19
  /**
20
  * $common_css
21
  *
22
+ * @var string
23
  * @since 7.3.5
24
  */
25
+ public $common_css = QSM_PLUGIN_CSS_URL . '/common.css';
26
+ public $mathjax_url = QSM_PLUGIN_JS_URL . '/mathjax/tex-mml-chtml.js';
27
  public $mathjax_version = '3.2.0';
28
 
29
  protected $qsm_background_email;
32
  *
33
  * Call functions within class
34
  *
35
+ * @since 4.0.0
36
+ * @uses QMNQuizManager::add_hooks() Adds actions to hooks and filters
37
  * @return void
38
  */
39
  public function __construct() {
45
  *
46
  * Adds functions to relavent hooks and filters
47
  *
48
+ * @since 4.0.0
49
  * @return void
50
  */
51
  public function add_hooks() {
58
  add_action( 'wp_ajax_nopriv_qsm_get_quiz_to_reload', array( $this, 'qsm_get_quiz_to_reload' ) );
59
  add_action( 'wp_ajax_qsm_get_question_quick_result', array( $this, 'qsm_get_question_quick_result' ) );
60
  add_action( 'wp_ajax_nopriv_qsm_get_question_quick_result', array( $this, 'qsm_get_question_quick_result' ) );
61
+ add_action( 'wp_ajax_qsm_export_data', array( $this, 'qsm_export_data' ) );
62
+ add_action( 'wp_ajax_nopriv_qsm_export_data', array( $this, 'qsm_export_data' ) );
63
+
64
+ add_action( 'wp_ajax_qsm_clear_audit_data', array( $this, 'qsm_clear_audit_data' ) );
65
+ add_action( 'wp_ajax_nopriv_qsm_clear_audit_data', array( $this, 'qsm_clear_audit_data' ) );
66
+
67
  // Upload file of file upload question type
68
  add_action( 'wp_ajax_qsm_upload_image_fd_question', array( $this, 'qsm_upload_image_fd_question' ) );
69
  add_action( 'wp_ajax_nopriv_qsm_upload_image_fd_question', array( $this, 'qsm_upload_image_fd_question' ) );
130
  }
131
 
132
  $uploaded_file['name'] = 'qsmfileupload_' . uniqid() . '_' . str_replace( '-', '_', $file_name );
133
+ $upload_overrides = array(
134
  'test_form' => false,
135
  );
136
+ $movefile = wp_handle_upload( $uploaded_file, $upload_overrides );
137
  if ( $movefile && ! isset( $movefile['error'] ) ) {
138
  // Prepare an array of post data for the attachment.
139
  $attachment = array(
146
  // Insert the attachment.
147
  $attach_id = wp_insert_attachment( $attachment, $movefile['file'], 0 );
148
  if ( $attach_id ) {
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
  }
228
  wp_die();
229
  }
230
 
231
+ /**
232
+ * Export CSV file
233
+ */
234
+
235
+ public function qsm_export_data() {
236
+ global $wpdb;
237
+ $export_tool_data = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}mlw_qm_audit_trail" );
238
+ // file creation
239
+ $qsm_export_filename = 'export_' . date( 'd-m-y' ) . '.csv';
240
+
241
+ // Clean object
242
+ ob_end_clean();
243
+
244
+ // Open file
245
+ $qsm_open_file = fopen( 'php://output', 'w' );
246
+ fputcsv( $qsm_open_file, array( 'Trail ID', 'User', 'Action', 'Quiz Name', 'Form Data', 'Time' ) );
247
+
248
+ // loop for insert data into CSV file
249
+ foreach ( $export_tool_data as $export_data ) {
250
+ $qsm_export_array = array(
251
+ 'trail_id' => $export_data->trail_id,
252
+ 'action_user' => $export_data->action_user,
253
+ 'action' => $export_data->action,
254
+ 'quiz_name' => $export_data->quiz_name,
255
+ 'form_data' => $export_data->form_data,
256
+ 'time' => $export_data->time,
257
+ );
258
+ fputcsv( $qsm_open_file, $qsm_export_array );
259
+ }
260
+
261
+ // download csv file
262
+ header( 'Content-Description: File Transfer' );
263
+ header( 'Content-Disposition: attachment; filename=' . $qsm_export_filename );
264
+ header( 'Content-Type: text/csv;' );
265
+ exit;
266
+
267
+ }
268
+
269
+ public function qsm_clear_audit_data() {
270
+ global $wpdb;
271
+ $table_audit = $wpdb->prefix . 'mlw_qm_audit_trail';
272
+ $wpdb->query( "TRUNCATE TABLE $table_audit" );
273
+
274
+ }
275
+
276
+
277
  /**
278
  * Generates Content For Quiz Shortcode
279
  *
280
  * Generates the content for the [mlw_quizmaster] shortcode
281
  *
282
+ * @since 4.0.0
283
+ * @param array $atts The attributes passed from the shortcode.
284
+ * @uses QMNQuizManager:load_questions() Loads questions
285
+ * @uses QMNQuizManager:create_answer_array() Prepares answers
286
+ * @uses QMNQuizManager:display_quiz() Generates and prepares quiz page
287
+ * @uses QMNQuizManager:display_results() Generates and prepares results page
288
  * @return string The content for the shortcode
289
  */
290
  public function display_shortcode( $atts ) {
297
  $atts
298
  );
299
 
300
+ $quiz = intval( $args['quiz'] );
301
  $question_amount = intval( $args['question_amount'] );
302
 
303
  ob_start();
309
  wp_enqueue_style( 'dashicons' );
310
  wp_enqueue_script( 'jquery' );
311
  wp_enqueue_script( 'jquery-ui-tooltip' );
312
+ wp_enqueue_script( 'qsm_quiz', QSM_PLUGIN_JS_URL . '/qsm-quiz.js', array( 'wp-util', 'underscore', 'jquery', 'jquery-ui-tooltip' ), $mlwQuizMasterNext->version, false );
313
+ wp_enqueue_script( 'qsm_common', QSM_PLUGIN_JS_URL . '/qsm-common.js', array(), $mlwQuizMasterNext->version, true );
314
+ wp_enqueue_script( 'math_jax', $this->mathjax_url, false, $this->mathjax_version, true );
315
  $result_unique_id = sanitize_text_field( wp_unslash( $_GET['result_id'] ) );
316
  $query = $wpdb->prepare( "SELECT result_id FROM {$wpdb->prefix}mlw_results WHERE unique_id = %s", $result_unique_id );
317
  $result = $wpdb->get_row( $query, ARRAY_A );
345
  /**
346
  * Filter Quiz Options before Quiz Display
347
  */
348
+ $qmn_quiz_options = apply_filters( 'qsm_shortcode_quiz_options', $qmn_quiz_options );
349
 
350
  // If quiz options isn't found, stop function.
351
  if ( is_null( $qmn_quiz_options ) || empty( $qmn_quiz_options->quiz_name ) ) {
356
  // The quiz_stye is misspelled because it has always been misspelled and fixing it would break many sites :(.
357
  if ( 'default' == $qmn_quiz_options->theme_selected ) {
358
  $return_display .= '<style type="text/css">' . preg_replace( '#<script(.*?)>(.*?)</script>#is', '', htmlspecialchars_decode( $qmn_quiz_options->quiz_stye ) ) . '</style>';
359
+ wp_enqueue_style( 'qmn_quiz_style', QSM_PLUGIN_CSS_URL . '/qmn_quiz.css', array(), $mlwQuizMasterNext->version );
360
  wp_style_add_data( 'qmn_quiz_style', 'rtl', 'replace' );
361
  } else {
362
  $registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates( $qmn_quiz_options->theme_selected );
369
  } elseif ( $registered_template && file_exists( get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'] ) ) {
370
  wp_enqueue_style( 'qmn_quiz_template', get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'], array(), $mlwQuizMasterNext->version );
371
  } else {
372
+ echo "<style type='text/css'>" . wp_kses_post( htmlspecialchars_decode( $qmn_quiz_options->quiz_stye ) ) . '</style>';
373
  }
374
  }
375
+ wp_enqueue_style( 'qmn_quiz_animation_style', QSM_PLUGIN_CSS_URL . '/animate.css', array(), $mlwQuizMasterNext->version );
376
  wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
377
  wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
378
  wp_enqueue_style( 'dashicons' );
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 ) ) {
396
  foreach ( $qpages_arr as $key => $qpage ) {
397
  unset( $qpage['questions'] );
418
  'quick_result_wrong_answer_text' => sanitize_text_field( $qmn_quiz_options->quick_result_wrong_answer_text ),
419
  'quiz_processing_message' => $qmn_quiz_options->quiz_processing_message,
420
  'not_allow_after_expired_time' => $qmn_quiz_options->not_allow_after_expired_time,
421
+ 'scheduled_time_end' => strtotime( $qmn_quiz_options->scheduled_time_end ),
422
  );
423
 
424
  $return_display = apply_filters( 'qmn_begin_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables, $atts );
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
  }
460
  global $wpdb;
461
  $result_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_results WHERE result_id = %d", $id ), ARRAY_A );
462
  if ( $result_data ) {
463
+ wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
464
  wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
465
  wp_enqueue_style( 'dashicons' );
466
+ wp_enqueue_style( 'qsm_primary_css', plugins_url( '../../templates/qmn_primary.css', __FILE__ ), array(), $mlwQuizMasterNext->version );
467
+ wp_enqueue_script( 'math_jax', $this->mathjax_url, false, $this->mathjax_version, true );
468
  $quiz_result = maybe_unserialize( $result_data['quiz_results'] );
469
  $response_data = array(
470
  'quiz_id' => $result_data['quiz_id'],
505
  *
506
  * Retrieves the questions from the database
507
  *
508
+ * @since 4.0.0
509
+ * @param int $quiz_id The id for the quiz.
510
+ * @param array $quiz_options The database row for the quiz.
511
+ * @param bool $is_quiz_page If the page being loaded is the quiz page or not.
512
+ * @param int $question_amount The amount of questions entered using the shortcode attribute.
513
+ * @return array The questions for the quiz
514
  * @deprecated 5.2.0 Use new class: QSM_Questions instead
515
  */
516
  public function load_questions( $quiz_id, $quiz_options, $is_quiz_page, $question_amount = 0 ) {
518
  // Prepare variables.
519
  global $wpdb;
520
  global $mlwQuizMasterNext;
521
+ $questions = array();
522
+ $order_by_sql = 'ORDER BY question_order ASC';
523
+ $limit_sql = '';
524
+ $big_array = array();
525
+ $exploded_arr = array();
526
  $multiple_category_system = false;
527
  // check if multiple category is enabled.
528
  $enabled = get_option( 'qsm_multiple_category_enabled' );
538
  if ( $categories ) {
539
  $exploded_arr = explode( ',', $quiz_options->randon_category );
540
  if ( ! $multiple_category_system ) {
541
+ $cat_str = "'" . implode( "', '", $exploded_arr ) . "'";
542
+ $cat_query = " AND category IN ( $cat_str ) ";
543
  } else {
544
+ $exploded_arr = array_map( 'intval', $exploded_arr );
545
  }
546
  }
547
  }
548
 
549
  // Check if we should load all questions or only a selcted amount.
550
+ if ( $is_quiz_page && ( 0 != $quiz_options->question_from_total || 0 !== $question_amount ) ) {
551
  if ( 0 !== $question_amount ) {
552
  $limit_sql = " LIMIT $question_amount";
553
  } else {
558
  // If using newer pages system from 5.2.
559
  $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
560
  // Get all question IDs needed.
561
+ $total_pages = count( $pages );
562
  $category_question_ids = array();
563
  if ( $multiple_category_system && ! empty( $exploded_arr ) ) {
564
+ $term_ids = implode( ', ', $exploded_arr );
565
+ $query = $wpdb->prepare( "SELECT DISTINCT question_id FROM {$wpdb->prefix}mlw_question_terms WHERE quiz_id = %d AND term_id IN (%1s)", $quiz_id, $term_ids );
566
  $question_data = $wpdb->get_results( $query, ARRAY_N );
567
  foreach ( $question_data as $q_data ) {
568
  $category_question_ids[] = $q_data[0];
573
  for ( $i = 0; $i < $total_pages; $i++ ) {
574
  foreach ( $pages[ $i ] as $question ) {
575
  if ( ! empty( $category_question_ids ) ) {
576
+ if ( in_array( intval( $question ), array_map( 'intval', $category_question_ids ), true ) ) {
577
  $question_ids[] = intval( $question );
578
  }
579
  } else {
582
  }
583
  }
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 ) {
598
  $term_data[ $val['term_id'] ][] = $val['question_id'];
599
  }
600
  if ( '' === $quiz_options->randon_category ) {
601
  foreach ( $categories_tree as $cat ) {
602
+ if ( ! empty( $cat->children ) ) {
603
+ unset( $term_data[ $cat->term_id ] );
604
  }
605
  }
606
  }
607
  foreach ( $term_data as $tv ) {
608
  if ( 1 == $quiz_options->randomness_order || 2 == $quiz_options->randomness_order ) {
609
+ shuffle( $tv );
610
  }
611
+ $random = array_merge( $random, array_slice( array_unique( $tv ), 0, $quiz_options->question_per_category ) );
612
  }
613
  }
614
  $question_ids = array_unique( $random );
617
  $question_ids = apply_filters( 'qsm_load_questions_ids', $question_ids, $quiz_id, $quiz_options );
618
  $question_sql = implode( ', ', $question_ids );
619
 
620
+ $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_questions WHERE question_id IN (%1s) %2s %3s %4s", $question_sql, $cat_query, $order_by_sql, $limit_sql );
621
+ $questions = $wpdb->get_results( stripslashes( $query ) );
622
 
623
  // If we are not using randomization, we need to put the questions in the order of the new question editor.
624
  // If a user has saved the pages in the question editor but still uses the older pagination options
625
  // Then they will make it here. So, we need to order the questions based on the new editor.
 
626
  if ( 1 != $quiz_options->randomness_order && 2 != $quiz_options->randomness_order && 0 == $quiz_options->question_per_category ) {
627
  $ordered_questions = array();
628
  foreach ( $questions as $question ) {
646
  $questions = apply_filters( 'qsm_load_questions_filter', $questions, $quiz_id, $quiz_options );
647
 
648
  // Create question ids array
649
+ $qsm_random_que_ids = array_column( $questions, 'question_id' );
650
  update_option( 'qsm_random_que_ids', $qsm_random_que_ids );
651
 
652
  // Returns an array of all the loaded questions.
658
  *
659
  * Prepares or creates the answer array for the quiz
660
  *
661
+ * @since 4.0.0
662
+ * @param array $questions The questions for the quiz.
663
+ * @param bool $is_ajax Pass true if this is an ajax call.
664
+ * @return array The answers for the quiz
665
  * @deprecated 5.2.0 Use new class: QSM_Questions instead
666
  */
667
  public function create_answer_array( $questions, $is_ajax = false ) {
671
  $question_list = array();
672
  foreach ( $questions as $mlw_question_info ) {
673
  $question_list[ $mlw_question_info->question_id ] = get_object_vars( $mlw_question_info );
674
+ $mlw_qmn_answer_array_each = maybe_unserialize( $mlw_question_info->answer_array );
675
  if ( is_array( $mlw_qmn_answer_array_each ) ) {
676
  $mlw_qmn_answer_arrays[ $mlw_question_info->question_id ] = $mlw_qmn_answer_array_each;
677
  $question_list[ $mlw_question_info->question_id ]['answers'] = $mlw_qmn_answer_array_each;
702
  *
703
  * Generates the content for the quiz page part of the shortcode
704
  *
705
+ * @since 4.0.0
706
+ * @param array $options The database row of the quiz.
707
+ * @param array $quiz_data The array of results for the quiz.
708
+ * @param int $question_amount The number of questions to load for quiz.
709
+ * @uses QMNQuizManager:display_begin_section() Creates display for beginning section
710
+ * @uses QMNQuizManager:display_questions() Creates display for questions
711
+ * @uses QMNQuizManager:display_comment_section() Creates display for comment section
712
+ * @uses QMNQuizManager:display_end_section() Creates display for end section
713
  * @return string The content for the quiz page section
714
  */
715
  public function display_quiz( $options, $quiz_data, $question_amount ) {
724
  wp_enqueue_script( 'jquery' );
725
  wp_enqueue_script( 'jquery-ui-core' );
726
  wp_enqueue_script( 'jquery-ui-tooltip' );
727
+ wp_enqueue_style( 'jquery-redmond-theme', QSM_PLUGIN_CSS_URL . '/jquery-ui.css', array(), $mlwQuizMasterNext->version );
728
 
729
  global $qmn_json_data;
730
  $qmn_json_data['error_messages'] = array(
734
  'empty' => sanitize_text_field( $options->empty_error_text ),
735
  );
736
 
737
+ wp_enqueue_script( 'progress-bar', QSM_PLUGIN_JS_URL . '/progressbar.min.js', array(), '1.1.0', true );
738
  wp_enqueue_script( 'jquery-ui-slider' );
739
+ wp_enqueue_script( 'jquery-ui-slider-rtl-js', QSM_PLUGIN_JS_URL . '/jquery.ui.slider-rtl.js', array(), $mlwQuizMasterNext->version, true );
740
+ wp_enqueue_style( 'jquery-ui-slider-rtl-css', QSM_PLUGIN_CSS_URL . '/jquery.ui.slider-rtl.css', array(), $mlwQuizMasterNext->version );
741
  wp_enqueue_script( 'jquery-touch-punch' );
742
+ wp_enqueue_style( 'qsm_model_css', QSM_PLUGIN_CSS_URL . '/qsm-admin.css', array(), $mlwQuizMasterNext->version );
743
  wp_style_add_data( 'qsm_model_css', 'rtl', 'replace' );
744
+ wp_enqueue_script( 'qsm_model_js', QSM_PLUGIN_JS_URL . '/micromodal.min.js', array(), $mlwQuizMasterNext->version, false );
745
+ wp_enqueue_script( 'qsm_quiz', QSM_PLUGIN_JS_URL . '/qsm-quiz.js', array( 'wp-util', 'underscore', 'jquery', 'jquery-ui-tooltip', 'progress-bar' ), $mlwQuizMasterNext->version, false );
746
+ wp_enqueue_script( 'qsm_common', QSM_PLUGIN_JS_URL . '/qsm-common.js', array(), $mlwQuizMasterNext->version, true );
747
  wp_localize_script(
748
  'qsm_quiz',
749
  'qmn_ajax_object',
756
  ),
757
  )
758
  );
759
+ wp_enqueue_script( 'math_jax', $this->mathjax_url, array(), $this->mathjax_version, true );
760
  global $qmn_total_questions;
761
  $qmn_total_questions = 0;
762
  global $mlw_qmn_section_count;
765
  // $saved_quiz_theme = $mlwQuizMasterNext->quiz_settings->get_setting('quiz_new_theme');
766
  $saved_quiz_theme = $mlwQuizMasterNext->theme_settings->get_active_quiz_theme_path( $options->quiz_id );
767
  $randomness_class = 0 === intval( $options->randomness_order ) ? '' : 'random';
768
+ ?><div class='qsm-quiz-container qmn_quiz_container mlw_qmn_quiz <?php echo esc_attr( $auto_pagination_class ); ?> quiz_theme_<?php echo esc_attr( $saved_quiz_theme . ' ' . $randomness_class ); ?> '>
769
+ <?php
770
  // Get quiz post based on quiz id
771
  $args = array(
772
  'posts_per_page' => 1,
792
  }
793
  echo apply_filters( 'qsm_display_before_form', '', $options, $quiz_data );
794
  $quiz_form_action = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
795
+ ?>
796
+ <form name="quizForm<?php echo esc_attr( $quiz_data['quiz_id'] ); ?>" id="quizForm<?php echo esc_attr( $quiz_data['quiz_id'] ); ?>" action="<?php echo esc_url( $quiz_form_action ); ?>" method="POST" class="qsm-quiz-form qmn_quiz_form mlw_quiz_form" novalidate enctype="multipart/form-data">
797
  <input type="hidden" name="qsm_hidden_questions" id="qsm_hidden_questions" value="">
798
  <div id="mlw_error_message" class="qsm-error-message qmn_error_message_section"></div>
799
+ <span id="mlw_top_of_quiz"></span>
800
+ <?php
801
  echo apply_filters( 'qmn_begin_quiz_form', '', $options, $quiz_data );
802
  // If deprecated pagination setting is not used, use new system...
803
  $pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );
805
  $this->display_pages( $options, $quiz_data );
806
  } else {
807
  // ... else, use older system.
808
+ $questions = $this->load_questions( $quiz_data['quiz_id'], $options, true, $question_amount );
809
+ $answers = $this->create_answer_array( $questions );
810
  $this->display_begin_section( $options, $quiz_data );
811
  echo apply_filters( 'qmn_begin_quiz_questions', '', $options, $quiz_data );
812
  $this->display_questions( $options, $questions, $answers );
822
  <input type="hidden" name="timer" id="timer" value="0" />
823
  <input type="hidden" name="timer_ms" id="timer_ms" value="0"/>
824
  <input type="hidden" class="qmn_quiz_id" name="qmn_quiz_id" id="qmn_quiz_id" value="<?php echo esc_attr( $quiz_data['quiz_id'] ); ?>" />
825
+ <input type='hidden' name='complete_quiz' value='confirmation' />
826
+ <?php
827
+ if ( isset( $_GET['payment_id'] ) && '' !== $_GET['payment_id'] ) {
828
+ $payment_id = sanitize_text_field( wp_unslash( $_GET['payment_id'] ) );
829
+ ?>
830
+ <input type="hidden" name="main_payment_id" value="<?php echo esc_attr( $payment_id ); ?>" />
831
+ <?php
832
+ }
833
+ echo apply_filters( 'qmn_end_quiz_form', '', $options, $quiz_data );
834
+ ?>
835
+ </form>
836
+ </div>
837
+ <?php
838
 
839
  echo apply_filters( 'qmn_end_quiz', '', $options, $quiz_data );
840
  }
842
  /**
843
  * Creates the pages of content for the quiz/survey
844
  *
845
+ * @since 5.2.0
846
+ * @param array $options The settings for the quiz.
847
+ * @param array $quiz_data The array of quiz data.
848
  * @return string The HTML for the pages
849
  */
850
  public function display_pages( $options, $quiz_data ) {
857
  $contact_fields = QSM_Contact_Manager::load_fields();
858
  $animation_effect = isset( $options->quiz_animation ) && '' !== $options->quiz_animation ? ' animated ' . $options->quiz_animation : '';
859
  $enable_pagination_quiz = isset( $options->enable_pagination_quiz ) && 1 == $options->enable_pagination_quiz ? true : false;
860
+
861
  if ( count( $pages ) > 1 && ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) ) {
862
  $qmn_json_data['first_page'] = true;
863
  $message_before = wpautop( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ) );
866
  <section class="qsm-page <?php echo esc_attr( $animation_effect ); ?>">
867
  <div class="quiz_section quiz_begin">
868
  <div class='qsm-before-message mlw_qmn_message_before'>
869
+ <?php
870
+ $editor_text = $wp_embed->run_shortcode( $message_before );
871
+ $editor_text = preg_replace( '/\s*[\w\/:\.]*youtube.com\/watch\?v=([\w]+)([\w\*\-\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $editor_text );
872
+ echo do_shortcode( wp_kses_post( $editor_text ) );
873
+ ?>
874
  </div>
875
+ <?php
876
+ if ( 0 == $options->contact_info_location ) {
877
+ echo QSM_Contact_Manager::display_fields( $options );
878
+ }
879
+ do_action( 'qsm_after_begin_message', $options, $quiz_data );
880
+ ?>
881
  </div>
882
  </section>
883
  <?php
887
  if ( 1 == count( $pages ) ) {
888
  ?>
889
  <section class="qsm-page <?php echo esc_attr( $animation_effect ); ?>">
890
+ <?php
891
+ if ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) {
892
+ $qmn_json_data['first_page'] = false;
893
+ $message_before = wpautop( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ) );
894
+ $message_before = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_before, $quiz_data );
895
+ ?>
896
  <div class="quiz_section quiz_begin">
897
  <div class='qsm-before-message mlw_qmn_message_before'>
898
+ <?php
899
+ $editor_text = $wp_embed->run_shortcode( $message_before );
900
+ $editor_text = preg_replace( '/\s*[\w\/:\.]*youtube.com\/watch\?v=([\w]+)([\w\*\-\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $editor_text );
901
+ echo do_shortcode( wp_kses_post( $editor_text ) );
902
+ ?>
903
  </div>
904
+ <?php
905
+ if ( 0 == $options->contact_info_location ) {
906
+ echo QSM_Contact_Manager::display_fields( $options );
 
 
 
 
907
  }
908
+ ?>
909
+ </div>
910
+ <?php
911
+ }
912
+ foreach ( $pages[0] as $question_id ) {
913
+ $question_list .= $question_id . 'Q';
914
+ $question = $questions[ $question_id ];
915
+ $category_class = '';
916
+ if ( ! empty( $question['multicategories'] ) ) {
917
+ foreach ( $question['multicategories'] as $cat ) {
918
+ $category_class .= ' category-section-id-c' . esc_attr( $cat );
919
  }
920
+ }
921
+ ?>
922
+ <div class="quiz_section qsm-question-wrapper question-section-id-<?php echo esc_attr( $question_id ); ?> <?php echo esc_attr( $category_class ); ?>" data-qid="<?php echo esc_attr( $question_id ); ?>">
923
+ <?php
924
+ $mlwQuizMasterNext->pluginHelper->display_question( $question['question_type_new'], $question_id, $options );
925
+ if ( 0 == $question['comments'] ) {
926
  ?>
927
+ <input type="text" class="qsm-question-comment qsm-question-comment-small mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
928
  <?php
929
  }
930
+ if ( 2 == $question['comments'] ) {
 
931
  ?>
932
+ <textarea class="qsm-question-comment qsm-question-comment-large mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" ></textarea>
933
+ <?php
934
+ }
935
+ // Checks if a hint is entered.
936
+ if ( ! empty( $question['hints'] ) ) {
937
+ echo '<div class="qsm-hint qsm_hint mlw_qmn_hint_link qsm_tooltip">' . wp_kses_post( $options->hint_text ) . '<span class="qsm_tooltiptext">' . wp_kses_post( $question['hints'] ) . '</span></div>';
938
+ }
939
+ ?>
940
+ </div>
941
+ <?php
942
+ }
943
+ if ( 0 == $options->comment_section ) {
944
+ $message_comments = wpautop( htmlspecialchars_decode( $options->message_comment, ENT_QUOTES ) );
945
+ ?>
946
  <div class="quiz_section quiz_begin">
947
  <label for='mlwQuizComments' class='qsm-comments-label mlw_qmn_comment_section_text'><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data ); ?></label>
948
  <textarea id='mlwQuizComments' name='mlwQuizComments' class='qsm-comments qmn_comment_section'></textarea>
949
  </div>
950
+ <?php
951
+ }
952
+ if ( ! empty( $options->message_end_template ) || ( 1 == $options->contact_info_location && $contact_fields ) ) {
953
+ $message_after = wpautop( htmlspecialchars_decode( $options->message_end_template, ENT_QUOTES ) );
954
+ ?>
955
  <div class="quiz_section">
956
  <div class='qsm-after-message mlw_qmn_message_end'><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data ); ?></div>
957
+ <?php
958
+ if ( 1 == $options->contact_info_location ) {
959
+ echo QSM_Contact_Manager::display_fields( $options );
 
 
 
 
960
  }
961
  ?>
962
+ </div>
963
+ <?php
964
+ }
965
+ ?>
966
  </section>
967
+ <?php
968
  } else {
969
  $total_pages_count = count( $pages );
970
  $pages_count = 1;
971
  foreach ( $pages as $key => $page ) {
972
+ $qpage = ( isset( $qpages[ $key ] ) ? $qpages[ $key ] : array() );
973
+ $qpage_id = ( isset( $qpage['id'] ) ? $qpage['id'] : $key );
974
+ $page_key = ( isset( $qpage['pagekey'] ) ? $qpage['pagekey'] : $key );
975
+ $hide_prevbtn = ( isset( $qpage['hide_prevbtn'] ) ? $qpage['hide_prevbtn'] : 0 );
976
  ?>
977
  <section class="qsm-page <?php echo esc_attr( $animation_effect ); ?> qsm-page-<?php echo esc_attr( $qpage_id ); ?>"
978
  data-pid="<?php echo esc_attr( $qpage_id ); ?>" data-prevbtn="<?php echo esc_attr( $hide_prevbtn ); ?>" style='display: none;'>
979
+ <?php do_action( 'qsm_action_before_page', $qpage_id, $qpage ); ?>
980
+ <?php
981
+ foreach ( $page as $question_id ) {
982
+ $question_list .= $question_id . 'Q';
983
+ $question = $questions[ $question_id ];
984
+ $category_class = '';
985
+ if ( ! empty( $question['multicategories'] ) ) {
986
+ foreach ( $question['multicategories'] as $cat ) {
987
+ $category_class .= ' category-section-id-c' . esc_attr( $cat );
 
988
  }
989
+ }
990
+ ?>
991
+ <div class='quiz_section qsm-question-wrapper question-section-id-<?php echo esc_attr( $question_id ); ?> <?php echo esc_attr( $category_class ); ?>' data-qid='<?php echo esc_attr( $question_id ); ?>'>
992
+ <?php
993
+ $mlwQuizMasterNext->pluginHelper->display_question( $question['question_type_new'], $question_id, $options );
994
+ if ( 0 == $question['comments'] ) {
995
  ?>
996
+ <input type="text" class="qsm-question-comment qsm-question-comment-small mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" />";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
997
  <?php
998
  }
999
+ if ( 2 == $question['comments'] ) {
1000
  ?>
1001
+ <textarea class="qsm-question-comment qsm-question-comment-large mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $question_id ); ?>" name="mlwComment<?php echo esc_attr( $question_id ); ?>" placeholder="<?php echo esc_attr( $options->comment_field_text ); ?>" onclick="qmnClearField(this)" ></textarea>";
1002
  <?php
1003
+ }
1004
+ // Checks if a hint is entered.
1005
+ if ( ! empty( $question['hints'] ) ) {
1006
+ echo '<div class="qsm-hint qsm_hint mlw_qmn_hint_link qsm_tooltip">' . wp_kses_post( $options->hint_text ) . '<span class="qsm_tooltiptext">' . wp_kses_post( $question['hints'] ) . '</span></div>';
1007
+ }
1008
+ ?>
1009
+ </div>
1010
+ <?php
1011
+ }
1012
+ if ( $enable_pagination_quiz ) {
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>
1020
+ <?php } ?>
1021
  </section>
1022
  <?php
1023
  $pages_count++;
1028
  ?>
1029
  <section class="qsm-page">
1030
  <div class="quiz_section quiz_begin">
1031
+ <label for="mlwQuizComments" class="qsm-comments-label mlw_qmn_comment_section_text"><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $quiz_data ); ?></label>
1032
+ <textarea id="mlwQuizComments" name="mlwQuizComments" class="qsm-comments qmn_comment_section"></textarea>
 
1033
  </div>
1034
  </section>
1035
  <?php
1036
  }
1037
+ if ( count( $pages ) > 1 && ( ! empty( $options->message_end_template ) || ( 1 == $options->contact_info_location && $contact_fields ) ) ) {
1038
+ $message_after = wpautop( htmlspecialchars_decode( $options->message_end_template, ENT_QUOTES ) );
1039
+ ?>
1040
  <section class="qsm-page" style="display: none;">
1041
  <div class="quiz_section">
1042
  <div class='qsm-after-message mlw_qmn_message_end'><?php echo apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_after, $quiz_data ); ?></div>
1043
  <?php
1044
+ if ( 1 == $options->contact_info_location ) {
1045
+ echo QSM_Contact_Manager::display_fields( $options );
1046
+ }
1047
+ ?>
1048
  </div>
1049
  <?php
1050
+ // Legacy code.
1051
+ do_action( 'mlw_qmn_end_quiz_section' );
1052
  ?>
1053
  </section>
1054
  <?php
1059
  *
1060
  * @since 7.3.5
1061
  */
1062
+ add_action(
1063
+ 'wp_footer',
1064
+ function () use ( $options ) {
1065
+ ?>
1066
  <!-- View for pagination -->
1067
  <script type="text/template" id="tmpl-qsm-pagination-<?php echo esc_attr( $options->quiz_id ); ?>">
1068
  <div class="qsm-pagination qmn_pagination border margin-bottom">
1074
  <input type='submit' class='qsm-btn qsm-submit-btn qmn_btn' value='<?php echo esc_attr( $options->submit_button_text ); ?>' />
1075
  </div>
1076
  </script>
1077
+ <?php
1078
+ }
1079
+ );
1080
  ?>
1081
  <input type="hidden" name="qmn_question_list" value="<?php echo esc_attr( $question_list ); ?>" />
1082
  <?php
1087
  *
1088
  * Generates the content for the beginning section of the quiz page
1089
  *
1090
+ * @since 4.0.0
1091
+ * @param array $qmn_quiz_options The database row of the quiz.
1092
+ * @param array $qmn_array_for_variables The array of results for the quiz.
1093
+ * @return string The content for the beginning section
1094
  * @deprecated 5.2.0 Use new page system instead
1095
  */
1096
  public function display_begin_section( $qmn_quiz_options, $qmn_array_for_variables ) {
1101
  global $mlw_qmn_section_count;
1102
  $mlw_qmn_section_count += 1;
1103
  $animation_effect = isset( $qmn_quiz_options->quiz_animation ) && '' !== $qmn_quiz_options->quiz_animation ? ' animated ' . $qmn_quiz_options->quiz_animation : '';
1104
+ ?>
1105
+ <div class="qsm-auto-page-row quiz_section <?php echo esc_attr( $animation_effect ); ?> quiz_begin">
1106
+ <?php
1107
+ $message_before = wpautop( htmlspecialchars_decode( $qmn_quiz_options->message_before, ENT_QUOTES ) );
1108
+ $message_before = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_before, $qmn_array_for_variables );
1109
+ $editor_text = $wp_embed->run_shortcode( $message_before );
1110
+ $editor_text = preg_replace( '/\s*[\w\/:\.]*youtube.com\/watch\?v=([\w]+)([\w\*\-\?\&\;\%\=\.]*)/i', '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $editor_text );
1111
+ ?>
1112
+ <div class='mlw_qmn_message_before'>
1113
+ <?php
1114
+ echo do_shortcode( wp_kses_post( $editor_text ) );
1115
+ ?>
1116
+ </div>
1117
+ <?php
1118
+ if ( 0 == $qmn_quiz_options->contact_info_location ) {
1119
+ echo QSM_Contact_Manager::display_fields( $qmn_quiz_options );
1120
+ }
1121
+ ?>
1122
+ </div>
1123
+ <?php
1124
  } else {
1125
  $qmn_json_data['first_page'] = false;
1126
  }
1131
  *
1132
  * Generates the content for the questions part of the quiz page
1133
  *
1134
+ * @since 4.0.0
1135
+ * @param array $qmn_quiz_options The database row of the quiz.
1136
+ * @param array $qmn_quiz_questions The questions of the quiz.
1137
+ * @param array $qmn_quiz_answers The answers of the quiz.
1138
+ * @uses QMNPluginHelper:display_question() Displays a question
1139
+ * @return string The content for the questions section
1140
  * @deprecated 5.2.0 Use new page system instead
1141
  */
1142
  public function display_questions( $qmn_quiz_options, $qmn_quiz_questions, $qmn_quiz_answers ) {
1156
  foreach ( $qmn_quiz_questions as $mlw_question ) {
1157
  if ( 0 != $pagination_optoin ) {
1158
  if ( 1 == $pagination_optoin ) {
1159
+ ?>
1160
+ <div class="qsm-auto-page-row qsm-apc-<?php echo esc_attr( $current_page_number ); ?>" style="display: none;">
1161
+ <?php
1162
  $current_page_number++;
1163
  } else {
1164
  if ( 1 == $pages_count % $pagination_optoin || 1 == $pages_count ) { // beginning of the row or first.
1165
+ ?>
1166
+ <div class="qsm-auto-page-row qsm-apc-<?php echo esc_attr( $current_page_number ); ?>" style="display: none;">
1167
+ <?php
1168
  $current_page_number++;
1169
  }
1170
  }
1171
  echo apply_filters( 'qsm_auto_page_begin_row', '', ( $current_page_number - 1 ), $qmn_quiz_options, $qmn_quiz_questions );
1172
  }
1173
+ $category_class = '';
1174
+ $multicategories = QSM_Questions::get_question_categories( $mlw_question->question_id );
1175
+ $question_categories = isset( $multicategories['category_tree'] ) && ! empty( $multicategories['category_tree'] ) ? array_keys( $multicategories['category_name'] ) : array();
1176
  if ( ! empty( $question_categories ) ) {
1177
  foreach ( $question_categories as $cat ) {
1178
  $category_class .= ' category-section-id-c' . esc_attr( $cat );
1180
  }
1181
 
1182
  $question_id_list .= $mlw_question->question_id . 'Q';
1183
+ ?>
1184
+ <div class="quiz_section qsm-question-wrapper <?php echo esc_attr( $animation_effect ); ?> question-section-id-<?php echo esc_attr( $mlw_question->question_id ); ?> slide<?php echo esc_attr( $mlw_qmn_section_count . ' ' . $category_class ); ?>">
1185
+ <?php
1186
  $mlwQuizMasterNext->pluginHelper->display_question( $mlw_question->question_type_new, $mlw_question->question_id, $qmn_quiz_options );
 
1187
  if ( 0 == $mlw_question->comments ) {
1188
+ ?>
1189
+ <input type="text" class="mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" name="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" placeholder="<?php echo esc_attr( $qmn_quiz_options->comment_field_text ); ?>" onclick="qmnClearField(this)" /><br />
1190
+ <?php
1191
  }
1192
  if ( 2 == $mlw_question->comments ) {
1193
+ ?>
1194
+ <textarea cols="70" rows="5" class="mlw_qmn_question_comment" id="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" name="mlwComment<?php echo esc_attr( $mlw_question->question_id ); ?>" placeholder="<?php echo esc_attr( $qmn_quiz_options->comment_field_text ); ?>" onclick="qmnClearField(this)"></textarea><br />
1195
+ <?php
1196
  }
 
1197
  // Checks if a hint is entered.
1198
  if ( ! empty( $mlw_question->hints ) ) {
1199
+ ?>
1200
+ <div class="qsm-hint qsm_hint mlw_qmn_hint_link qsm_tooltip"><?php echo esc_html( $qmn_quiz_options->hint_text ); ?><span class="qsm_tooltiptext"><?php echo wp_kses( preg_replace( '#<script(.*?)>(.*?)</script>#is', '', htmlspecialchars_decode( $mlw_question->hints, ENT_QUOTES ) ), wp_kses_allowed_html( 'post' ) ); ?></span></div><br /><br />
1201
+ <?php
1202
  }
1203
+ ?>
1204
+ </div><!-- .quiz_section -->
1205
+ <?php
1206
  if ( 0 == $pagination_optoin ) {
1207
 
1208
  } elseif ( 1 == $pagination_optoin || 0 == $pages_count % $pagination_optoin || count( $qmn_quiz_questions ) == $pages_count ) { // end of the row or last
1209
+ ?>
1210
+ </div><!-- .qsm-auto-page-row -->
1211
+ <?php
1212
  }
1213
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1214
  $pages_count++;
1215
  }
1216
  if ( $enable_pagination_quiz ) {
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>
1224
+ <?php
1225
  }
1226
+ ?>
1227
+ <input type="hidden" name="qmn_question_list" value="<?php echo esc_attr( $question_id_list ); ?>" />
1228
+ <?php
1229
  }
1230
 
1231
  /**
1233
  *
1234
  * Generates the content for the comment section part of the quiz page
1235
  *
1236
+ * @since 4.0.0
1237
+ * @param array $qmn_quiz_options The database row of the quiz.
1238
+ * @param array $qmn_array_for_variables The array of results for the quiz.
1239
+ * @return string The content for the comment section
1240
  * @deprecated 5.2.0 Use new page system instead
1241
  */
1242
  public function display_comment_section( $qmn_quiz_options, $qmn_array_for_variables ) {
1243
  global $mlw_qmn_section_count;
1244
  if ( 0 == $qmn_quiz_options->comment_section ) {
1245
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1246
+ $qsm_d_none = 0 == $qmn_quiz_options->randomness_order ? 'qsm-d-none' : '';
1247
  ?>
1248
+ <div class="quiz_section quiz_end qsm-auto-page-row qsm-quiz-comment-section slide <?php echo esc_attr( $mlw_qmn_section_count . ' ' . $qsm_d_none ); ?>" >
1249
  <?php
1250
+ $message_comments = wpautop( htmlspecialchars_decode( $qmn_quiz_options->message_comment, ENT_QUOTES ) );
1251
+ $message_comments = apply_filters( 'mlw_qmn_template_variable_quiz_page', $message_comments, $qmn_array_for_variables );
1252
+ ?>
1253
+ <label for="mlwQuizComments" class="mlw_qmn_comment_section_text"><?php echo wp_kses( $message_comments, wp_kses_allowed_html( 'post' ) ); ?></label><br />
1254
  <textarea cols="60" rows="10" id="mlwQuizComments" name="mlwQuizComments" class="qmn_comment_section"></textarea>
1255
+ </div>
1256
+ <?php
1257
  }
1258
  }
1259
 
1262
  *
1263
  * Generates the content for the end section of the quiz page
1264
  *
1265
+ * @since 4.0.0
1266
+ * @param array $qmn_quiz_options The database row of the quiz.
1267
+ * @param array $qmn_array_for_variables The array of results for the quiz.
1268
+ * @return string The content for the end section
1269
  * @deprecated 5.2.0 Use new page system instead
1270
  */
1271
  public function display_end_section( $qmn_quiz_options, $qmn_array_for_variables ) {
1272
  global $mlw_qmn_section_count;
1273
+ $section_display = '';
1274
  $mlw_qmn_section_count = $mlw_qmn_section_count + 1;
1275
  $pagination_optoin = $qmn_quiz_options->pagination;
1276
  // Legacy Code.
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>
1298
+ <?php
1299
  } else {
1300
+ ?>
1301
+ <div class="qsm-auto-page-row quiz_section quiz_end empty_quiz_end <?php echo esc_attr( $qsm_d_none ); ?>" >
1302
  <input type="submit" class="qsm-btn qsm-submit-btn qmn_btn" value="<?php echo esc_attr( $qmn_quiz_options->submit_button_text ); ?>" />
1303
+ </div>
1304
+ <?php
1305
  }
1306
  }
1307
 
1310
  *
1311
  * Generates the content for the results page part of the shortcode
1312
  *
1313
+ * @since 4.0.0
1314
+ * @param array $options The database row of the quiz.
1315
+ * @param array $data The array of results for the quiz.
1316
+ * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
1317
  * @return string The content for the results page section
1318
  */
1319
  public function display_results( $options, $data ) {
1325
  /**
1326
  * Calls the results page from ajax
1327
  *
1328
+ * @since 4.6.0
1329
+ * @uses QMNQuizManager:submit_results() Perform The Quiz/Survey Submission
1330
  * @return string The content for the results page section
1331
  */
1332
  public function ajax_submit_results() {
1336
  $qmn_allowed_visit = true;
1337
  $quiz = isset( $_POST['qmn_quiz_id'] ) ? intval( $_POST['qmn_quiz_id'] ) : '';
1338
  $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
1339
+ $options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
1340
  $qsm_option = isset( $options->quiz_settings ) ? maybe_unserialize( $options->quiz_settings ) : array();
1341
  $qsm_option = array_map( 'maybe_unserialize', $qsm_option );
1342
+ $dateStr = $qsm_option['quiz_options']['scheduled_time_end'];
1343
+ $timezone = isset( $_POST['currentuserTimeZone'] ) ? sanitize_text_field( wp_unslash( $_POST['currentuserTimeZone'] ) ) : '';
1344
+ $dtUtcDate = strtotime( $dateStr . ' ' . $timezone );
1345
 
1346
  if ( '1' === $qsm_option['quiz_options']['not_allow_after_expired_time'] && isset( $_POST['currentuserTime'] ) && sanitize_text_field( wp_unslash( $_POST['currentuserTime'] ) ) > $dtUtcDate ) {
1347
  echo wp_json_encode( array( 'quizExpired' => true ) );
1390
  *
1391
  * Prepares and save the results, prepares and send emails, prepare results page
1392
  *
1393
+ * @since 4.6.0
1394
+ * @param array $qmn_quiz_options The database row of the quiz.
1395
+ * @param array $qmn_array_for_variables The array of results for the quiz.
1396
+ * @uses QMNQuizManager:check_answers() Creates display for beginning section
1397
+ * @uses QMNQuizManager:check_comment_section() Creates display for questions
1398
+ * @uses QMNQuizManager:display_results_text() Creates display for end section
1399
+ * @uses QMNQuizManager:display_social() Creates display for comment section
1400
+ * @uses QMNQuizManager:send_user_email() Creates display for end section
1401
+ * @uses QMNQuizManager:send_admin_email() Creates display for end section
1402
  * @return string The content for the results page section
1403
  */
1404
  public function submit_results( $qmn_quiz_options, $qmn_array_for_variables ) {
1447
  }
1448
  }
1449
 
1450
+ $mlw_qmn_pagetime = isset( $_POST['pagetime'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['pagetime'] ) ) : array();
1451
+ $mlw_qmn_timer = isset( $_POST['timer'] ) ? intval( $_POST['timer'] ) : 0;
1452
+ $mlw_qmn_timer_ms = isset( $_POST['timer_ms'] ) ? intval( $_POST['timer_ms'] ) : 0;
1453
+ $qmn_array_for_variables['user_id'] = get_current_user_id();
1454
+ $qmn_array_for_variables['timer'] = $mlw_qmn_timer;
1455
+ $qmn_array_for_variables['timer_ms'] = $mlw_qmn_timer_ms;
1456
+ $qmn_array_for_variables['time_taken'] = current_time( 'h:i:s A m/d/Y' );
1457
+ $qmn_array_for_variables['contact'] = $contact_responses;
1458
+ $hidden_questions = array();
1459
  if ( isset( $_POST['qsm_hidden_questions'] ) ) {
1460
+ $hidden_questions = sanitize_text_field( wp_unslash( $_POST['qsm_hidden_questions'] ) );
1461
+ $hidden_questions = json_decode( $hidden_questions, true );
1462
  }
1463
  $qmn_array_for_variables['hidden_questions'] = $hidden_questions;
1464
  $qmn_array_for_variables = apply_filters( 'qsm_result_variables', $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 );
1472
+ $unique_id = uniqid();
1473
+ $results_id = 0;
1474
  // If the store responses in database option is set to Yes.
1475
  if ( 0 != $qmn_quiz_options->store_responses ) {
1476
  // Creates our results array.
1509
  array( 'result_id' => $results_id )
1510
  );
1511
  } else {
1512
+ $http_referer = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
1513
  $results_insert = $wpdb->insert(
1514
  $table_name,
1515
  array(
1532
  'deleted' => 0,
1533
  'unique_id' => $unique_id,
1534
  'form_type' => isset( $qmn_quiz_options->form_type ) ? $qmn_quiz_options->form_type : 0,
1535
+ 'page_url' => $http_referer,
1536
+ 'page_name' => url_to_postid( $http_referer ) ? get_the_title( url_to_postid( $http_referer ) ) : '',
1537
  ),
1538
  array(
1539
  '%d',
1555
  '%d',
1556
  '%s',
1557
  '%d',
1558
+ '%s',
1559
+ '%s',
1560
  )
1561
  );
1562
  $results_id = $wpdb->insert_id;
1563
  }
1564
  }
1565
+ $qmn_array_for_variables['response_saved'] = isset( $results_insert ) ? $results_insert : false;
1566
+ $qmn_array_for_variables['result_id'] = $results_id;
1567
  $qmn_array_for_variables['result_unique_id'] = $unique_id;
1568
 
1569
  // Converts date to the preferred format
1570
  global $mlwQuizMasterNext;
1571
+ $qmn_array_for_variables = $mlwQuizMasterNext->pluginHelper->convert_to_preferred_date_format( $qmn_array_for_variables );
1572
 
1573
  // Determines redirect/results page.
1574
  $results_pages = $this->display_results_text( $qmn_quiz_options, $qmn_array_for_variables );
1578
  $result_display .= $this->display_social( $qmn_quiz_options, $qmn_array_for_variables );
1579
  $result_display = apply_filters( 'qmn_after_social_media', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
1580
  if ( 1 == $qmn_quiz_options->enable_retake_quiz_button ) {
 
1581
  $result_display .= '<form method="POST">';
1582
  $result_display .= '<input type="hidden" value="' . $qmn_array_for_variables['quiz_id'] . '" name="qsm_retake_quiz_id" />';
1583
+ $result_display .= '<input type="submit" value="' . apply_filters( 'qsm_retake_quiz_text', __( 'Retake Quiz', 'quiz-master-next' ) ) . '" name="qsm_retake_button" />';
1584
  $result_display .= '</form>';
1585
  }
1586
 
1587
  /*
1588
+ * Update the option `qmn_quiz_taken_cnt` value by 1 each time
1589
+ * whenever the record inserted into the required table.
1590
+ */
1591
  if ( $results_insert ) {
1592
  $rec_inserted = intval( get_option( 'qmn_quiz_taken_cnt' ) );
1593
  if ( 1000 > $rec_inserted ) {
1661
  *
1662
  * Calculates the users scores for the quiz
1663
  *
1664
+ * @since 4.0.0
1665
+ * @param array $options The database row of the quiz
1666
+ * @param array $quiz_data The array of results for the quiz
1667
+ * @uses QMNPluginHelper:display_review() Scores the question
1668
  * @return array The results of the user's score
1669
  */
1670
  public static function check_answers( $options, $quiz_data ) {
1684
  }
1685
 
1686
  // Prepare variables
1687
+ $points_earned = 0;
1688
+ $total_correct = 0;
1689
+ $total_score = 0;
1690
+ $user_answer = '';
1691
+ $correct_answer = '';
1692
+ $correct_status = 'incorrect';
1693
+ $answer_points = 0;
1694
+ $question_data = array();
1695
+ $total_possible_points = 0;
1696
+ $attempted_question = 0;
1697
  $minimum_possible_points = 0;
1698
  // Question types to calculate result on
1699
  $result_question_types = array(
1710
  13, // Polar.
1711
  );
1712
 
1713
+ // Advance Question types filter
1714
+ $result_question_types = apply_filters( 'qsm_result_question_types', $result_question_types );
1715
+
1716
  // If deprecated pagination setting is not used, use new system...
1717
  if ( 0 == $options->question_from_total && 0 !== count( $pages ) ) {
1718
  // Cycle through each page in quiz.
1723
  foreach ( $question_list as $question_id ) {
1724
  // When the questions are the same...
1725
  if ( $page_question_id == $question_id ) {
1726
+ $question = $questions[ $page_question_id ];
1727
+ $question_type_new = $question['question_type_new'];
1728
+ // Ignore non points questions from result.
1729
+ $hidden_questions = is_array( $quiz_data['hidden_questions'] ) ? $quiz_data['hidden_questions'] : array();
1730
 
1731
+ // Reset question-specific variables.
1732
  $user_answer = '';
1733
  $correct_answer = '';
1734
  $correct_status = 'incorrect';
1735
  $answer_points = 0;
1736
 
1737
+ // Get maximum and minimum points for the quiz.
1738
  if ( ! in_array( intval( $question_id ), $hidden_questions, true ) ) {
1739
+ $max_min_result = self::qsm_max_min_points( $options, $question );
1740
+ $total_possible_points += $max_min_result['max_point'];
1741
  $minimum_possible_points += $max_min_result['min_point'];
1742
  }
1743
 
1812
  // Cycle through each page in quiz.
1813
  foreach ( $questions as $question ) {
1814
 
1815
+ // Cycle through each question that appeared to the user.
1816
  foreach ( $question_list as $question_id ) {
1817
 
1818
  // When the questions are the same...
1819
  if ( $question['question_id'] == $question_id ) {
1820
+ // Reset question-specific variables.
1821
  $user_answer = '';
1822
  $correct_answer = '';
1823
  $correct_status = 'incorrect';
1824
  $answer_points = 0;
1825
 
1826
+ // Get maximum and minimum points for the quiz.
1827
+ $max_min_result = self::qsm_max_min_points( $options, $question );
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.
1836
  $points_earned += $results_array['points'];
1837
  $answer_points += $results_array['points'];
1838
 
1839
+ // If the user's answer was correct.
1840
  if ( 'correct' == $results_array['correct'] ) {
1841
  $total_correct += 1;
1842
  $correct_status = 'correct';
1849
  $attempted_question++;
1850
  }
1851
  }
1852
+ // If a comment was submitted.
1853
  if ( isset( $_POST[ 'mlwComment' . $question['question_id'] ] ) ) {
1854
  $comment = htmlspecialchars( sanitize_textarea_field( wp_unslash( $_POST[ 'mlwComment' . $question['question_id'] ] ) ), ENT_QUOTES );
1855
  } else {
1889
  }
1890
  }
1891
 
 
1892
  // Calculate Total Percent Score And Average Points Only If Total Questions Doesn't Equal Zero To Avoid Division By Zero Error
1893
  if ( 0 !== $total_questions ) {
1894
  $total_score = round( ( ( $total_correct / $total_questions ) * 100 ), 2 );
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();
1907
  foreach ( $qsm_random_que_ids as $que_id ) {
1908
+ $key = array_search( $que_id, $qs_ids, true );
1909
  $new_question_data[] = $question_data[ $key ];
1910
  }
1911
  if ( ! empty( $new_question_data ) ) {
1917
  }
1918
 
1919
  // Return array to be merged with main user response array
1920
+ return apply_filters(
1921
+ 'qsm_check_answers_results',
1922
+ array(
1923
+ 'total_points' => $points_earned,
1924
+ 'total_score' => $total_score,
1925
+ 'total_correct' => $total_correct,
1926
+ 'total_questions' => $total_questions,
1927
+ 'question_answers_display' => '', // Kept for backwards compatibility
1928
+ 'question_answers_array' => $question_data,
1929
+ 'total_possible_points' => $total_possible_points,
1930
+ 'total_attempted_questions' => $attempted_question,
1931
+ 'minimum_possible_points' => $minimum_possible_points,
1932
+ ),
1933
+ $options,
1934
+ $quiz_data
1935
+ );
1936
  }
1937
 
1938
  /**
1940
  *
1941
  * Checks to see if the user left a comment and returns the comment
1942
  *
1943
+ * @since 4.0.0
1944
+ * @param array $qmn_quiz_options The database row of the quiz
1945
+ * @param array $qmn_array_for_variables The array of results for the quiz
1946
  * @return string The user's comments
1947
  */
1948
  public function check_comment_section( $qmn_quiz_options, $qmn_array_for_variables ) {
1956
  /**
1957
  * computes maximum and minimum points for a quiz
1958
  *
1959
+ * @since 7.3.5
1960
+ * @param array $options
1961
+ * @param array $question
1962
  * @return string $max_min_result
1963
  */
1964
+ public static function qsm_max_min_points( $options, $question ) {
1965
 
1966
  $max_value_array = array();
1967
  $min_value_array = array();
1968
 
1969
+ $valid_grading_system = ( 1 == $options->system || 3 == $options->system );
1970
+ $valid_answer_array = ( isset( $question['answers'] ) && ! empty( $question['answers'] ) );
1971
 
1972
  $max_min_result = array(
1973
  'max_point' => 0,
1974
  'min_point' => 0,
1975
  );
1976
 
1977
+ if ( ! ( $valid_answer_array && $valid_grading_system ) ) {
1978
+ return $max_min_result;
1979
  }
1980
 
1981
  foreach ( $question['answers'] as $single_answerk_key => $single_answer_arr ) {
1982
+ if ( isset( $single_answer_arr[1] ) ) {
1983
+ $single_answer_arr[1] = apply_filters( 'qsm_single_answer_arr', $single_answer_arr[1] );
1984
+ if ( intval( $single_answer_arr[1] ) > 0 ) {
1985
+ array_push( $max_value_array, $single_answer_arr[1] );
1986
+ }
1987
+ if ( intval( $single_answer_arr[1] ) < 0 ) {
1988
+ array_push( $min_value_array, $single_answer_arr[1] );
1989
+ }
1990
  }
1991
  }
 
1992
 
1993
+ $question_type = $question['question_type_new'];
1994
+ $question_required = ( 0 === maybe_unserialize( $question['question_settings'] )['required'] );
1995
+ $multi_response = ( '4' === $question_type || '10' === $question_type );
1996
 
1997
+ return self::qsm_max_min_points_conditions( $max_value_array, $min_value_array, $question_required, $multi_response );
1998
 
1999
  }
2000
  /**
2001
  * evaluates conditions and returns maximum and minimum points for a quiz
2002
  *
2003
+ * @since 7.3.5
2004
+ * @param array $max_value_array
2005
+ * @param array $min_value_array
2006
+ * @param array $question_required
2007
+ * @param array $multi_response
2008
  * @return string $max_min_result
2009
  */
2010
+ public static function qsm_max_min_points_conditions( $max_value_array, $min_value_array, $question_required, $multi_response ) {
2011
  $max_min_result = array(
2012
  'max_point' => 0,
2013
  'min_point' => 0,
2014
  );
2015
+ if ( empty( $max_value_array ) && empty( $min_value_array ) ) {
2016
+ return $max_min_result;
2017
  }
2018
+ if ( empty( $max_value_array ) && $question_required && $multi_response ) {
2019
+ $max_min_result['max_point'] = max( $min_value_array );
2020
+ $max_min_result['min_point'] = array_sum( $min_value_array );
2021
  }
2022
+ if ( empty( $max_value_array ) && $question_required && ! $multi_response ) {
2023
+ $max_min_result['max_point'] = max( $min_value_array );
2024
+ $max_min_result['min_point'] = min( $min_value_array );
2025
  }
2026
+ if ( empty( $max_value_array ) && ! $question_required && $multi_response ) {
2027
+ $max_min_result['max_point'] = 0;
2028
+ $max_min_result['min_point'] = array_sum( $min_value_array );
2029
  }
2030
+ if ( empty( $max_value_array ) && ! $question_required && ! $multi_response ) {
2031
+ $max_min_result['max_point'] = 0;
2032
+ $max_min_result['min_point'] = min( $min_value_array );
2033
  }
2034
+ if ( empty( $min_value_array ) && $question_required && $multi_response ) {
2035
+ $max_min_result['min_point'] = min( $max_value_array );
2036
+ $max_min_result['max_point'] = array_sum( $max_value_array );
2037
  }
2038
+ if ( empty( $min_value_array ) && $question_required && ! $multi_response ) {
2039
+ $max_min_result['min_point'] = min( $max_value_array );
2040
+ $max_min_result['max_point'] = max( $max_value_array );
2041
  }
2042
+ if ( empty( $min_value_array ) && ! $question_required && $multi_response ) {
2043
+ $max_min_result['min_point'] = 0;
2044
+ $max_min_result['max_point'] = array_sum( $max_value_array );
2045
  }
2046
+ if ( empty( $min_value_array ) && ! $question_required && ! $multi_response ) {
2047
+ $max_min_result['min_point'] = 0;
2048
+ $max_min_result['max_point'] = max( $max_value_array );
2049
  }
2050
+ if ( ! empty( $max_value_array ) && ! empty( $min_value_array ) && $multi_response ) {
2051
+ $max_min_result['max_point'] = array_sum( $max_value_array );
2052
+ $max_min_result['min_point'] = array_sum( $min_value_array );
2053
  }
2054
+ if ( ! empty( $max_value_array ) && ! empty( $min_value_array ) && ! $multi_response ) {
2055
+ $max_min_result['max_point'] = max( $max_value_array );
2056
+ $max_min_result['min_point'] = min( $min_value_array );
2057
  }
2058
  return $max_min_result;
2059
  }
2061
  /**
2062
  * Displays Results Text
2063
  *
2064
+ * @since 4.0.0
2065
  * @deprecated 6.1.0 Use the newer results page class instead.
2066
+ * @param array $options The quiz settings.
2067
+ * @param array $response_data The array of results for the quiz.
2068
+ * @return string The contents for the results text
2069
  */
2070
  public function display_results_text( $options, $response_data ) {
2071
  return QSM_Results_Pages::generate_pages( $response_data );
2075
  * Displays social media buttons
2076
  *
2077
  * @deprecated 6.1.0 Use the social media template variables instead.
2078
+ * @since 4.0.0
2079
+ * @param array $qmn_quiz_options The database row of the quiz.
2080
+ * @param array $qmn_array_for_variables The array of results for the quiz.
2081
+ * @return string The content of the social media button section
2082
  */
2083
  public function display_social( $qmn_quiz_options, $qmn_array_for_variables ) {
2084
  $social_display = '';
2110
  * Prepares the email to the user and then sends the email
2111
  *
2112
  * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
2113
+ * @since 4.0.0
2114
+ * @param array $qmn_quiz_options The database row of the quiz
2115
+ * @param array $qmn_array_for_variables The array of results for the quiz
2116
  */
2117
  public function send_user_email( $qmn_quiz_options, $qmn_array_for_variables ) {
2118
  add_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
2215
  * Prepares the email to the admin and then sends the email
2216
  *
2217
  * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
2218
+ * @since 4.0.0
2219
+ * @param array $qmn_quiz_options The database row of the quiz
2220
+ * @param arrar $qmn_array_for_variables The array of results for the quiz
2221
  */
2222
  public function send_admin_email( $qmn_quiz_options, $qmn_array_for_variables ) {
2223
  // Switch email type to HTML
2243
  }
2244
  }
2245
 
2246
+ $mlw_message = '';
2247
+ $mlw_subject = '';
2248
  $mlw_admin_email_array = maybe_unserialize( $qmn_quiz_options->admin_email_template );
2249
  if ( is_array( $mlw_admin_email_array ) ) {
2250
  // Cycle through landing pages
2322
  /**
2323
  * Returns the quiz taker's IP if IP collection is enabled
2324
  *
2325
+ * @since 5.3.0
2326
  * @return string The IP address or a phrase if not collected
2327
  */
2328
  private function get_user_ip() {
2364
  *
2365
  * @since 6.4.11
2366
  *
2367
+ * @param string $plugin Path to the plugin file relative to the plugins directory.
2368
  * @return bool True, if in the active plugins list. False, not in the list.
2369
  */
2370
  private function qsm_plugin_active( $plugin ) {
2376
  *
2377
  * @since 6.4.11
2378
  *
2379
+ * @param string $plugin Path to the plugin file relative to the plugins directory.
2380
  * @return bool True if active for the network, otherwise false.
2381
  */
2382
  private function qsm_plugin_active_for_network() {
2398
  * @singce 7.0
2399
  */
2400
  public function qsm_process_background_email() {
2401
+ include_once plugin_dir_path( __FILE__ ) . 'class-qmn-background-process.php';
2402
  $this->qsm_background_email = new QSM_Background_Request();
2403
  }
2404
 
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
 
2471
  * @since 7.0.0 Added the condition for start time ( end time blank ) and end time ( start time blank ).
2472
  *
2473
  * @global boolean $qmn_allowed_visit
2474
+ * @param HTML $display
2475
+ * @param Object $options
2476
+ * @param Array $variable_data
2477
  * @return HTML This function check the time frame of quiz.
2478
  */
2479
  function qsm_scheduled_timeframe_check( $display, $options, $variable_data ) {
2522
  /**
2523
  * Checks if user has already reach the user limit of the quiz
2524
  *
2525
+ * @since 5.0.0
2526
+ * @param string $display The HTML displayed for the quiz
2527
+ * @param array $qmn_quiz_options The settings for the quiz
2528
+ * @param array $qmn_array_for_variables The array of data by the quiz
2529
  * @return string The altered HTML display for the quiz
2530
  */
2531
  function qmn_total_user_tries_check( $display, $qmn_quiz_options, $qmn_array_for_variables ) {
 
2532
  global $qmn_allowed_visit;
2533
  if ( 0 != $qmn_quiz_options->total_user_tries ) {
2534
 
2651
  return $display;
2652
  }
2653
 
2654
+ // This function helps set the email type to HTML
2655
 
2656
  function mlw_qmn_set_html_content_type() {
2657
  return 'text/html';
2660
  function qsm_time_in_milliseconds() {
2661
  return round( microtime( true ) * 1000 );
2662
  }
2663
+ add_filter(
2664
+ 'wp_video_extensions',
2665
+ function ( $exts ) {
2666
  $exts[] = 'mov';
2667
  $exts[] = 'avi';
2668
  $exts[] = 'wmv';
php/classes/class-qsm-audit.php CHANGED
@@ -1,48 +1,55 @@
1
  <?php
2
 
3
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
4
 
5
  /**
6
  * This class handles the audit trail of the plugin
7
  */
8
  class QSM_Audit {
9
- /**
10
- * Adds new audit to Audit Trail table
11
- *
12
- * @since 4.7.1
13
- * @param string $action The action that is to be saved into the audit trail
14
- * @return bool Returns true if successfull and false if fails
15
- */
16
- public function new_audit( $action, $user = null ) {
17
- // Sanitizes action just in case 3rd party uses this funtion
18
- $action = sanitize_text_field( $action );
19
-
20
- // Retrieves current user's data
21
- if ( is_null( $user ) ) {
22
- $current_user = wp_get_current_user();
23
- } else {
24
- $current_user = $user;
25
- }
26
 
27
  // Returns if the current user is not valid
28
  if ( ! ( $current_user instanceof WP_User ) ) {
29
  return false;
30
  }
31
-
32
- global $wpdb;
33
-
 
34
  // Inserts new audit into table
35
  $inserted = $wpdb->insert(
36
- $wpdb->prefix . "mlw_qm_audit_trail",
37
  array(
38
  'action_user' => $current_user->display_name,
39
  'action' => $action,
40
- 'time' => gmdate("h:i:s A m/d/Y"),
 
 
 
41
  ),
42
  array(
43
  '%s',
44
  '%s',
45
  '%s',
 
 
 
46
  )
47
  );
48
 
@@ -51,7 +58,7 @@ class QSM_Audit {
51
  return false;
52
  }
53
 
54
- return true;
55
- }
56
  }
57
 
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
 
7
  /**
8
  * This class handles the audit trail of the plugin
9
  */
10
  class QSM_Audit {
11
+
12
+ /**
13
+ * Adds new audit to Audit Trail table
14
+ *
15
+ * @since 4.7.1
16
+ * @param string $action The action that is to be saved into the audit trail
17
+ * @return bool Returns true if successfull and false if fails
18
+ */
19
+ public function new_audit( $action, $quiz_id, $json_updated_setting_data ) {
20
+
21
+ // Sanitizes action just in case 3rd party uses this funtion
22
+ $action = sanitize_text_field( $action );
23
+
24
+ // Retrieves current user's data
25
+ $current_user = wp_get_current_user();
 
 
26
 
27
  // Returns if the current user is not valid
28
  if ( ! ( $current_user instanceof WP_User ) ) {
29
  return false;
30
  }
31
+ $quiz_id = esc_attr( $quiz_id );
32
+ global $wpdb;
33
+ $quiz_name = $wpdb->get_var( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $quiz_id ) );
34
+ $quiz_name = esc_attr( $quiz_name );
35
  // Inserts new audit into table
36
  $inserted = $wpdb->insert(
37
+ $wpdb->prefix . 'mlw_qm_audit_trail',
38
  array(
39
  'action_user' => $current_user->display_name,
40
  'action' => $action,
41
+ 'quiz_id' => $quiz_id,
42
+ 'quiz_name' => $quiz_name,
43
+ 'form_data' => $json_updated_setting_data,
44
+ 'time' => date( 'h:i:s A m/d/Y' ),
45
  ),
46
  array(
47
  '%s',
48
  '%s',
49
  '%s',
50
+ '%s',
51
+ '%s',
52
+ '%s',
53
  )
54
  );
55
 
58
  return false;
59
  }
60
 
61
+ return true;
62
+ }
63
  }
64
 
php/classes/class-qsm-emails.php CHANGED
@@ -23,7 +23,7 @@ class QSM_Emails {
23
  * @param array $response_data The data for the user's submission.
24
  */
25
  public static function send_emails( $response_data ) {
26
- $emails = QSM_Emails::load_emails( $response_data['quiz_id'] );
27
 
28
  if ( ! is_array( $emails ) || empty( $emails ) ) {
29
  return;
@@ -47,9 +47,9 @@ class QSM_Emails {
47
 
48
  // Cycle through each condition to see if we should sent this email.
49
  foreach ( $email['conditions'] as $condition ) {
50
- $value = $condition['value'];
51
  $category = '';
52
- if ( isset($condition['category']) ) {
53
  $category = $condition['category'];
54
  }
55
  // First, determine which value we need to test.
@@ -129,10 +129,10 @@ class QSM_Emails {
129
  }
130
 
131
  if ( $show ) {
132
- QSM_Emails::send_results_email( $response_data, $email['to'], $email['subject'], $email['content'], $email['replyTo'] );
133
  }
134
  } else {
135
- QSM_Emails::send_results_email( $response_data, $email['to'], $email['subject'], $email['content'], $email['replyTo'] );
136
  }
137
  }
138
 
@@ -161,21 +161,40 @@ class QSM_Emails {
161
  } else {
162
  $to = str_replace( '%USER_EMAIL%', '', $to );
163
  }
164
- $to = apply_filters('qsm_send_results_email_addresses', $to, $response_data);
165
  $to_array = explode( ',', $to );
166
- $to_array = array_unique($to_array);
167
- if ( empty($to_array) ) {
168
  return;
169
  }
170
  // Prepares our subject.
171
  $subject = apply_filters( 'mlw_qmn_template_variable_results_page', $subject, $response_data );
172
  // Prepares our content.
 
 
 
 
173
  $response_data['email_template_array'] = true;
174
- $content = apply_filters( 'mlw_qmn_template_variable_results_page', $content, $response_data );
175
- $content = htmlspecialchars_decode( $content, ENT_QUOTES );
176
- //convert css classes to inline
177
- $content = $mlwQuizMasterNext->pluginHelper->qsm_results_css_inliner($content);
178
- $content = html_entity_decode( $content );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  // Prepares our from name and email.
181
  $settings = (array) get_option( 'qmn-settings' );
@@ -214,7 +233,7 @@ class QSM_Emails {
214
  /**
215
  * Filter to modify email headers.
216
  */
217
- $headers = apply_filters('qsm_send_results_email_headers', $headers, $response_data);
218
 
219
  // Prepares our attachments. If %USER_EMAIL% was in the $to, then use the user email attachment filter.
220
  $attachments = array();
@@ -250,18 +269,18 @@ class QSM_Emails {
250
 
251
  global $wpdb;
252
  $data = $wpdb->get_var( $wpdb->prepare( "SELECT user_email_template FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ) );
253
-
254
  $data = maybe_unserialize( $data );
255
  // Checks if the emails is an array.
256
  if ( is_array( $data ) ) {
257
  // Checks if the emails array is not the newer version.
258
  if ( ! empty( $data ) && ! isset( $data[0]['conditions'] ) ) {
259
- $emails = QSM_Emails::convert_to_new_system( $quiz_id );
260
  } else {
261
  $emails = $data;
262
  }
263
  } else {
264
- $emails = QSM_Emails::convert_to_new_system( $quiz_id );
265
  }
266
 
267
  return $emails;
@@ -291,7 +310,7 @@ class QSM_Emails {
291
  $data = $wpdb->get_row( $wpdb->prepare( "SELECT send_user_email, user_email_template, send_admin_email, admin_email_template, email_from_text, admin_email FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ), ARRAY_A );
292
  $system = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'system', 0 );
293
  if ( 0 === intval( $data['send_user_email'] ) ) {
294
- $emails = array_merge( $emails, QSM_Emails::convert_emails( $system, $data['user_email_template'] ) );
295
  }
296
  if ( 0 === intval( $data['send_admin_email'] ) ) {
297
  $from_email_array = maybe_unserialize( $data['email_from_text'] );
@@ -300,7 +319,7 @@ class QSM_Emails {
300
  'reply_to' => 1,
301
  );
302
  }
303
- $emails = array_merge( $emails, QSM_Emails::convert_emails( $system, $data['admin_email_template'], $data['admin_email'], $from_email_array['reply_to'] ) );
304
  }
305
 
306
  // Updates the database with new array to prevent running this step next time.
23
  * @param array $response_data The data for the user's submission.
24
  */
25
  public static function send_emails( $response_data ) {
26
+ $emails = self::load_emails( $response_data['quiz_id'] );
27
 
28
  if ( ! is_array( $emails ) || empty( $emails ) ) {
29
  return;
47
 
48
  // Cycle through each condition to see if we should sent this email.
49
  foreach ( $email['conditions'] as $condition ) {
50
+ $value = $condition['value'];
51
  $category = '';
52
+ if ( isset( $condition['category'] ) ) {
53
  $category = $condition['category'];
54
  }
55
  // First, determine which value we need to test.
129
  }
130
 
131
  if ( $show ) {
132
+ self::send_results_email( $response_data, $email['to'], $email['subject'], $email['content'], $email['replyTo'] );
133
  }
134
  } else {
135
+ self::send_results_email( $response_data, $email['to'], $email['subject'], $email['content'], $email['replyTo'] );
136
  }
137
  }
138
 
161
  } else {
162
  $to = str_replace( '%USER_EMAIL%', '', $to );
163
  }
164
+ $to = apply_filters( 'qsm_send_results_email_addresses', $to, $response_data );
165
  $to_array = explode( ',', $to );
166
+ $to_array = array_unique( $to_array );
167
+ if ( empty( $to_array ) ) {
168
  return;
169
  }
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 );
198
 
199
  // Prepares our from name and email.
200
  $settings = (array) get_option( 'qmn-settings' );
233
  /**
234
  * Filter to modify email headers.
235
  */
236
+ $headers = apply_filters( 'qsm_send_results_email_headers', $headers, $response_data );
237
 
238
  // Prepares our attachments. If %USER_EMAIL% was in the $to, then use the user email attachment filter.
239
  $attachments = array();
269
 
270
  global $wpdb;
271
  $data = $wpdb->get_var( $wpdb->prepare( "SELECT user_email_template FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ) );
272
+
273
  $data = maybe_unserialize( $data );
274
  // Checks if the emails is an array.
275
  if ( is_array( $data ) ) {
276
  // Checks if the emails array is not the newer version.
277
  if ( ! empty( $data ) && ! isset( $data[0]['conditions'] ) ) {
278
+ $emails = self::convert_to_new_system( $quiz_id );
279
  } else {
280
  $emails = $data;
281
  }
282
  } else {
283
+ $emails = self::convert_to_new_system( $quiz_id );
284
  }
285
 
286
  return $emails;
310
  $data = $wpdb->get_row( $wpdb->prepare( "SELECT send_user_email, user_email_template, send_admin_email, admin_email_template, email_from_text, admin_email FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ), ARRAY_A );
311
  $system = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'system', 0 );
312
  if ( 0 === intval( $data['send_user_email'] ) ) {
313
+ $emails = array_merge( $emails, self::convert_emails( $system, $data['user_email_template'] ) );
314
  }
315
  if ( 0 === intval( $data['send_admin_email'] ) ) {
316
  $from_email_array = maybe_unserialize( $data['email_from_text'] );
319
  'reply_to' => 1,
320
  );
321
  }
322
+ $emails = array_merge( $emails, self::convert_emails( $system, $data['admin_email_template'], $data['admin_email'], $from_email_array['reply_to'] ) );
323
  }
324
 
325
  // Updates the database with new array to prevent running this step next time.
php/classes/class-qsm-fields.php CHANGED
@@ -20,6 +20,8 @@ class QSM_Fields {
20
  global $mlwQuizMasterNext;
21
  global $wpdb;
22
  $result_page_fb_image = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_text', 'result_page_fb_image' );
 
 
23
  // If nonce is correct, save settings
24
  if ( isset( $_POST["save_settings_nonce"] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['save_settings_nonce'] ) ), 'save_settings' ) ) {
25
  // Cycle through fields to retrieve all posted values
@@ -57,12 +59,15 @@ class QSM_Fields {
57
  }
58
  $settings_array[ $field["id"] ] = $sanitized_value;
59
  }
 
60
 
61
  // Update the settings and show alert based on outcome
62
  $results = $mlwQuizMasterNext->pluginHelper->update_quiz_setting( $section, $settings_array );
63
  if ( false !== $results ) {
 
 
64
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The settings has been updated successfully.', 'quiz-master-next' ), 'success' );
65
- $mlwQuizMasterNext->audit_manager->new_audit( 'Settings Have Been Edited' );
66
  } else {
67
  $mlwQuizMasterNext->alertManager->newAlert( __( 'There was an error when updating the settings. Please try again.', 'quiz-master-next' ), 'error');
68
  }
20
  global $mlwQuizMasterNext;
21
  global $wpdb;
22
  $result_page_fb_image = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_text', 'result_page_fb_image' );
23
+ $settings_array_before_update = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( $section );
24
+
25
  // If nonce is correct, save settings
26
  if ( isset( $_POST["save_settings_nonce"] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['save_settings_nonce'] ) ), 'save_settings' ) ) {
27
  // Cycle through fields to retrieve all posted values
59
  }
60
  $settings_array[ $field["id"] ] = $sanitized_value;
61
  }
62
+ $quiz_id = isset( $_GET["quiz_id"] ) ? intval( $_GET["quiz_id"] ) : 0;
63
 
64
  // Update the settings and show alert based on outcome
65
  $results = $mlwQuizMasterNext->pluginHelper->update_quiz_setting( $section, $settings_array );
66
  if ( false !== $results ) {
67
+ $get_updated_setting_data = array_diff_assoc($settings_array, $settings_array_before_update);
68
+ $json_updated_setting_data = wp_json_encode($get_updated_setting_data);
69
  $mlwQuizMasterNext->alertManager->newAlert( __( 'The settings has been updated successfully.', 'quiz-master-next' ), 'success' );
70
+ $mlwQuizMasterNext->audit_manager->new_audit( 'Settings Have Been Edited', $quiz_id, $json_updated_setting_data );
71
  } else {
72
  $mlwQuizMasterNext->alertManager->newAlert( __( 'There was an error when updating the settings. Please try again.', 'quiz-master-next' ), 'error');
73
  }
php/classes/class-qsm-install.php CHANGED
@@ -1366,6 +1366,9 @@ class QSM_Install {
1366
  trail_id mediumint(9) NOT NULL AUTO_INCREMENT,
1367
  action_user TEXT NOT NULL,
1368
  action TEXT NOT NULL,
 
 
 
1369
  time TEXT NOT NULL,
1370
  PRIMARY KEY (trail_id)
1371
  ) $charset_collate;";
@@ -1803,6 +1806,8 @@ class QSM_Install {
1803
 
1804
  global $wpdb;
1805
  $table_name = $wpdb->prefix . 'mlw_results';
 
 
1806
  // Update 2.6.4
1807
  if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'user'" ) != 'user' ) {
1808
  $sql = 'ALTER TABLE ' . $table_name . ' ADD user INT NOT NULL AFTER phone';
@@ -1822,6 +1827,16 @@ class QSM_Install {
1822
  if ( $wpdb->get_var( "select data_type from information_schema.columns where table_name = '" . $wpdb->prefix . "mlw_results' and column_name = 'point_score'" ) != 'FLOAT' ) {
1823
  $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results MODIFY point_score FLOAT NOT NULL;' );
1824
  }
 
 
 
 
 
 
 
 
 
 
1825
  // Update 5.0.0
1826
  $settings = (array) get_option( 'qmn-settings', array() );
1827
  if ( ! isset( $settings['results_details_template'] ) ) {
1366
  trail_id mediumint(9) NOT NULL AUTO_INCREMENT,
1367
  action_user TEXT NOT NULL,
1368
  action TEXT NOT NULL,
1369
+ quiz_id TEXT NOT NULL,
1370
+ quiz_name TEXT NOT NULL,
1371
+ form_data TEXT NOT NULL,
1372
  time TEXT NOT NULL,
1373
  PRIMARY KEY (trail_id)
1374
  ) $charset_collate;";
1806
 
1807
  global $wpdb;
1808
  $table_name = $wpdb->prefix . 'mlw_results';
1809
+ $audit_table = $wpdb->prefix . 'mlw_qm_audit_trail';
1810
+
1811
  // Update 2.6.4
1812
  if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $table_name . " LIKE 'user'" ) != 'user' ) {
1813
  $sql = 'ALTER TABLE ' . $table_name . ' ADD user INT NOT NULL AFTER phone';
1827
  if ( $wpdb->get_var( "select data_type from information_schema.columns where table_name = '" . $wpdb->prefix . "mlw_results' and column_name = 'point_score'" ) != 'FLOAT' ) {
1828
  $results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results MODIFY point_score FLOAT NOT NULL;' );
1829
  }
1830
+
1831
+ if ( $wpdb->get_var( 'SHOW COLUMNS FROM ' . $audit_table . " LIKE 'quiz_id'" ) != 'quiz_id' ) {
1832
+ $sql = 'ALTER TABLE ' . $audit_table . ' ADD quiz_id TEXT NOT NULL AFTER action';
1833
+ $results = $wpdb->query( $sql );
1834
+ $sql = 'ALTER TABLE ' . $audit_table . ' ADD quiz_name TEXT NOT NULL AFTER quiz_id';
1835
+ $results = $wpdb->query( $sql );
1836
+ $sql = 'ALTER TABLE ' . $audit_table . ' ADD form_data TEXT NOT NULL AFTER quiz_name';
1837
+ $results = $wpdb->query( $sql );
1838
+
1839
+ }
1840
  // Update 5.0.0
1841
  $settings = (array) get_option( 'qmn-settings', array() );
1842
  if ( ! isset( $settings['results_details_template'] ) ) {
php/classes/class-qsm-questions.php CHANGED
@@ -12,11 +12,12 @@
12
  */
13
  class QSM_Questions {
14
 
 
15
  /**
16
  * Loads single question using question ID
17
  *
18
- * @since 5.2.0
19
- * @param int $question_id The ID of the question.
20
  * @return array The data for the question.
21
  */
22
  public static function load_question( $question_id ) {
@@ -24,9 +25,9 @@ class QSM_Questions {
24
  $question_id = intval( $question_id );
25
  $question = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_questions WHERE question_id = %d LIMIT 1", $question_id ), 'ARRAY_A' );
26
  if ( ! is_null( $question ) ) {
27
- $multicategories = array();
28
- $multicategories_res = $wpdb->get_results("SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id`='{$question['question_id']}' AND `taxonomy`='qsm_category'", ARRAY_A);
29
- if ( ! empty($multicategories_res) ) {
30
  foreach ( $multicategories_res as $cat ) {
31
  $multicategories[] = $cat['term_id'];
32
  }
@@ -53,8 +54,8 @@ class QSM_Questions {
53
  /**
54
  * Loads questions for a quiz using the new page system
55
  *
56
- * @since 5.2.0
57
- * @param int $quiz_id The ID of the quiz.
58
  * @return array The array of questions.
59
  */
60
  public static function load_questions_by_pages( $quiz_id ) {
@@ -82,7 +83,7 @@ class QSM_Questions {
82
  }
83
  }
84
  }
85
-
86
  // If we have any question IDs, get the questions.
87
  if ( count( $question_ids ) > 0 ) {
88
 
@@ -93,11 +94,11 @@ class QSM_Questions {
93
 
94
  // Loop through questions and prepare serialized data.
95
  foreach ( $question_array as $question ) {
96
- $multicategories = self::get_question_categories($question['question_id']);
97
- //get_question_categories
98
 
99
- $question['multicategories'] = isset($multicategories['category_tree']) && ! empty($multicategories['category_tree'] ) ? array_keys($multicategories['category_name']) : array();
100
- $question['multicategoriesobject'] = isset($multicategories['category_tree']) && ! empty($multicategories['category_tree'] ) ? $multicategories['category_tree'] : array();
101
  // Prepares settings.
102
  $settings = maybe_unserialize( $question['question_settings'] );
103
  if ( ! is_array( $settings ) ) {
@@ -129,8 +130,8 @@ class QSM_Questions {
129
  /**
130
  * Loads questions for a quiz
131
  *
132
- * @since 5.2.0
133
- * @param int $quiz_id The ID of the quiz.
134
  * @return array The array of questions.
135
  */
136
  public static function load_questions( $quiz_id ) {
@@ -148,9 +149,9 @@ class QSM_Questions {
148
 
149
  // Loop through questions and prepare serialized data.
150
  foreach ( $questions as $question ) {
151
- $multicategories = array();
152
- $multicategories_res = $wpdb->get_results("SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id`='{$question['question_id']}' AND `taxonomy`='qsm_category'", ARRAY_A);
153
- if ( ! empty($multicategories_res) ) {
154
  foreach ( $multicategories_res as $cat ) {
155
  $multicategories[] = $cat['term_id'];
156
  }
@@ -177,10 +178,10 @@ class QSM_Questions {
177
  /**
178
  * Creates a new question
179
  *
180
- * @since 5.2.0
181
- * @param array $data The question data.
182
- * @param array $answers The answers for the question.
183
- * @param array $settings Any settings for the question.
184
  * @throws Exception Throws exception if wpdb query results in error.
185
  * @return int The ID of the question that was created.
186
  */
@@ -191,11 +192,11 @@ class QSM_Questions {
191
  /**
192
  * Saves a question
193
  *
194
- * @since 5.2.0
195
- * @param int $question_id The ID of the question to be saved.
196
- * @param array $data The question data.
197
- * @param array $answers The answers for the question.
198
- * @param array $settings Any settings for the question.
199
  * @throws Exception Throws exception if wpdb query results in error.
200
  * @return int The ID of the question that was saved.
201
  */
@@ -207,8 +208,8 @@ class QSM_Questions {
207
  /**
208
  * Deletes a question
209
  *
210
- * @since 5.2.0
211
- * @param int $question_id The ID for the question.
212
  * @throws Exception Throws exception if wpdb query results in error.
213
  * @return bool True if successful
214
  */
@@ -241,11 +242,11 @@ class QSM_Questions {
241
  *
242
  * This is used internally. Use create_question or save_question instead.
243
  *
244
- * @since 5.2.0
245
- * @param array $data The question data.
246
- * @param array $answers The answers for the question.
247
- * @param array $settings Any settings for the question.
248
- * @param bool $is_creating True if question is being created, false if being saved.
249
  * @throws Exception Throws exception if wpdb query results in error.
250
  * @return int The ID of the question that was created/saved.
251
  */
@@ -272,8 +273,19 @@ class QSM_Questions {
272
  $settings = wp_parse_args( $settings, $defaults );
273
 
274
  $answers = self::sanitize_answers( $answers, $settings );
 
 
 
 
 
 
 
 
 
 
 
275
 
276
- $question_name = htmlspecialchars( wp_kses_post( $data['name'] ), ENT_QUOTES );
277
  $trim_question_description = apply_filters( 'qsm_trim_question_description', true );
278
  if ( $trim_question_description ) {
279
  $question_name = trim( preg_replace( '/\s+/', ' ', $question_name ) );
@@ -292,7 +304,7 @@ class QSM_Questions {
292
  'category' => sanitize_text_field( $data['category'] ),
293
  'deleted' => 0,
294
  );
295
- $values = apply_filters('qsm_save_question_data', $values);
296
 
297
  $types = array(
298
  '%d',
@@ -309,15 +321,15 @@ class QSM_Questions {
309
  );
310
 
311
  if ( $is_creating ) {
312
- $results = $wpdb->insert(
313
  $wpdb->prefix . 'mlw_questions',
314
  $values,
315
  $types
316
  );
317
  $question_id = $wpdb->insert_id;
318
  } else {
319
- $question_id = intval($data['ID']);
320
- $results = $wpdb->update(
321
  $wpdb->prefix . 'mlw_questions',
322
  $values,
323
  array( 'question_id' => $question_id ),
@@ -335,20 +347,23 @@ class QSM_Questions {
335
  /**
336
  * Process Question Categories
337
  */
338
- $question_terms_table = $wpdb->prefix . "mlw_question_terms";
339
- $wpdb->delete($question_terms_table, array(
340
- 'question_id' => $question_id,
341
- 'taxonomy' => 'qsm_category',
342
- ));
343
- if ( ! empty($data['multicategories']) ) {
 
 
 
344
  foreach ( $data['multicategories'] as $term_id ) {
345
  $term_rel_data = array(
346
  'question_id' => $question_id,
347
- 'quiz_id' => intval($data['quiz_id']),
348
  'term_id' => $term_id,
349
  'taxonomy' => 'qsm_category',
350
  );
351
- $wpdb->insert($question_terms_table, $term_rel_data);
352
  }
353
  }
354
 
@@ -360,27 +375,19 @@ class QSM_Questions {
360
  *
361
  * sanitizes answers
362
  *
363
- * @since 7.3.5
364
- * @param array $answers The answers for the question.
365
  * @return array sanitized $answers The answers for the question.
366
  */
367
  public static function sanitize_answers( $answers, $settings ) {
368
 
369
  foreach ( $answers as $key => $answer ) {
370
  if ( 'rich' == $settings['answerEditor'] ) {
371
- $answer_text = wp_kses_post( $answer[0] );
372
  } else {
373
- $answer_text = sanitize_text_field( $answer[0] );
374
- }
375
- $answers_array = array(
376
- htmlspecialchars( $answer_text, ENT_QUOTES ),
377
- floatval( $answer[1] ),
378
- intval( $answer[2] ),
379
- );
380
- if ( isset( $answer[3] ) ) {
381
- array_push( $answers_array, htmlspecialchars( $answer[3], ENT_QUOTES ) );
382
  }
383
- $answers[ $key ] = $answers_array;
384
  }
385
 
386
  return $answers;
@@ -389,22 +396,21 @@ class QSM_Questions {
389
  /**
390
  * Get categories for a quiz
391
  *
392
- * @since 7.2.1
393
- * @param int $quiz_id The ID of the quiz.
394
  * @return array The array of categories.
395
  */
396
  public static function get_quiz_categories( $quiz_id = 0 ) {
397
  global $wpdb;
398
  $categories = array();
399
  if ( 0 !== $quiz_id ) {
400
- $questions = QSM_Questions::load_questions_by_pages( $quiz_id );
401
- $question_ids = array_column( $questions, 'question_id' );
402
- $question_ids = implode( ',', $question_ids );
403
- $question_terms = $wpdb->get_results( "SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id` IN ({$question_ids}) AND `taxonomy`='qsm_category'", ARRAY_A );
404
- $term_ids = ! empty( $question_terms ) ? array_unique( array_column( $question_terms, 'term_id' ) ) : array();
405
-
406
- $cat_array = self::get_question_categories_from_quiz_id( $quiz_id );
407
- $enabled = get_option( 'qsm_multiple_category_enabled' );
408
  if ( $enabled && 'cancelled' !== $enabled && ! empty( $cat_array ) ) {
409
  $term_ids = array_unique( array_merge( $term_ids, $cat_array ) );
410
  }
@@ -417,8 +423,8 @@ class QSM_Questions {
417
  /**
418
  * Get categories from quiz id
419
  *
420
- * @since 7.3.3
421
- * @param int $quiz_id The ID of the quiz.
422
  * @return array The array of categories.
423
  */
424
  public static function get_question_categories_from_quiz_id( $quiz_id ) {
@@ -437,22 +443,24 @@ class QSM_Questions {
437
  /**
438
  * Get categories from term ids
439
  *
440
- * @since 7.3.3
441
- * @param int $term_ids Term IDs of the quiz.
442
  * @return array The array of categories.
443
  */
444
  public static function get_question_categories_from_term_ids( $term_ids ) {
445
  $categories = array();
446
  if ( ! empty( $term_ids ) ) {
447
- $categories_names = array();
448
- $categories_tree = array();
449
- $terms = get_terms( array(
450
- 'taxonomy' => 'qsm_category',
451
- 'include' => $term_ids,
452
- 'hide_empty' => false,
453
- 'orderby' => '',
454
- 'order' => '',
455
- ) );
 
 
456
  if ( ! empty( $terms ) ) {
457
  foreach ( $terms as $tax ) {
458
  $categories_names[ $tax->term_id ] = $tax->name;
@@ -471,26 +479,28 @@ class QSM_Questions {
471
  /**
472
  * Get categories for a Question
473
  *
474
- * @since 7.2.1
475
- * @param int $quiz_id The ID of the quiz.
476
  * @return array The array of categories.
477
  */
478
  public static function get_question_categories( $question_id = 0 ) {
479
  global $wpdb;
480
- $categories_tree = array();
481
- $categories_names = array();
482
  if ( 0 !== $question_id ) {
483
  $question_terms = $wpdb->get_results( "SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id`='{$question_id}' AND `taxonomy`='qsm_category'", ARRAY_A );
484
  if ( ! empty( $question_terms ) ) {
485
  $term_ids = array_unique( array_column( $question_terms, 'term_id' ) );
486
  if ( ! empty( $term_ids ) ) {
487
- $terms = get_terms( array(
488
- 'taxonomy' => 'qsm_category',
489
- 'include' => array_unique( $term_ids ),
490
- 'hide_empty' => false,
491
- 'orderby' => '',
492
- 'order' => '',
493
- ) );
 
 
494
  if ( ! empty( $terms ) ) {
495
  foreach ( $terms as $tax ) {
496
  $categories_names[ $tax->term_id ] = $tax->name;
@@ -503,8 +513,8 @@ class QSM_Questions {
503
  }
504
  }
505
  return array(
506
- 'category_name' => $categories_names,
507
- "category_tree" => $categories_tree,
508
  );
509
  }
510
  /**
12
  */
13
  class QSM_Questions {
14
 
15
+
16
  /**
17
  * Loads single question using question ID
18
  *
19
+ * @since 5.2.0
20
+ * @param int $question_id The ID of the question.
21
  * @return array The data for the question.
22
  */
23
  public static function load_question( $question_id ) {
25
  $question_id = intval( $question_id );
26
  $question = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_questions WHERE question_id = %d LIMIT 1", $question_id ), 'ARRAY_A' );
27
  if ( ! is_null( $question ) ) {
28
+ $multicategories = array();
29
+ $multicategories_res = $wpdb->get_results( "SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id`='{$question['question_id']}' AND `taxonomy`='qsm_category'", ARRAY_A );
30
+ if ( ! empty( $multicategories_res ) ) {
31
  foreach ( $multicategories_res as $cat ) {
32
  $multicategories[] = $cat['term_id'];
33
  }
54
  /**
55
  * Loads questions for a quiz using the new page system
56
  *
57
+ * @since 5.2.0
58
+ * @param int $quiz_id The ID of the quiz.
59
  * @return array The array of questions.
60
  */
61
  public static function load_questions_by_pages( $quiz_id ) {
83
  }
84
  }
85
  }
86
+
87
  // If we have any question IDs, get the questions.
88
  if ( count( $question_ids ) > 0 ) {
89
 
94
 
95
  // Loop through questions and prepare serialized data.
96
  foreach ( $question_array as $question ) {
97
+ $multicategories = self::get_question_categories( $question['question_id'] );
98
+ // get_question_categories
99
 
100
+ $question['multicategories'] = isset( $multicategories['category_tree'] ) && ! empty( $multicategories['category_tree'] ) ? array_keys( $multicategories['category_name'] ) : array();
101
+ $question['multicategoriesobject'] = isset( $multicategories['category_tree'] ) && ! empty( $multicategories['category_tree'] ) ? $multicategories['category_tree'] : array();
102
  // Prepares settings.
103
  $settings = maybe_unserialize( $question['question_settings'] );
104
  if ( ! is_array( $settings ) ) {
130
  /**
131
  * Loads questions for a quiz
132
  *
133
+ * @since 5.2.0
134
+ * @param int $quiz_id The ID of the quiz.
135
  * @return array The array of questions.
136
  */
137
  public static function load_questions( $quiz_id ) {
149
 
150
  // Loop through questions and prepare serialized data.
151
  foreach ( $questions as $question ) {
152
+ $multicategories = array();
153
+ $multicategories_res = $wpdb->get_results( "SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id`='{$question['question_id']}' AND `taxonomy`='qsm_category'", ARRAY_A );
154
+ if ( ! empty( $multicategories_res ) ) {
155
  foreach ( $multicategories_res as $cat ) {
156
  $multicategories[] = $cat['term_id'];
157
  }
178
  /**
179
  * Creates a new question
180
  *
181
+ * @since 5.2.0
182
+ * @param array $data The question data.
183
+ * @param array $answers The answers for the question.
184
+ * @param array $settings Any settings for the question.
185
  * @throws Exception Throws exception if wpdb query results in error.
186
  * @return int The ID of the question that was created.
187
  */
192
  /**
193
  * Saves a question
194
  *
195
+ * @since 5.2.0
196
+ * @param int $question_id The ID of the question to be saved.
197
+ * @param array $data The question data.
198
+ * @param array $answers The answers for the question.
199
+ * @param array $settings Any settings for the question.
200
  * @throws Exception Throws exception if wpdb query results in error.
201
  * @return int The ID of the question that was saved.
202
  */
208
  /**
209
  * Deletes a question
210
  *
211
+ * @since 5.2.0
212
+ * @param int $question_id The ID for the question.
213
  * @throws Exception Throws exception if wpdb query results in error.
214
  * @return bool True if successful
215
  */
242
  *
243
  * This is used internally. Use create_question or save_question instead.
244
  *
245
+ * @since 5.2.0
246
+ * @param array $data The question data.
247
+ * @param array $answers The answers for the question.
248
+ * @param array $settings Any settings for the question.
249
+ * @param bool $is_creating True if question is being created, false if being saved.
250
  * @throws Exception Throws exception if wpdb query results in error.
251
  * @return int The ID of the question that was created/saved.
252
  */
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] ),
280
+ intval( $answer[2] ),
281
+ );
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 );
290
  if ( $trim_question_description ) {
291
  $question_name = trim( preg_replace( '/\s+/', ' ', $question_name ) );
304
  'category' => sanitize_text_field( $data['category'] ),
305
  'deleted' => 0,
306
  );
307
+ $values = apply_filters( 'qsm_save_question_data', $values );
308
 
309
  $types = array(
310
  '%d',
321
  );
322
 
323
  if ( $is_creating ) {
324
+ $results = $wpdb->insert(
325
  $wpdb->prefix . 'mlw_questions',
326
  $values,
327
  $types
328
  );
329
  $question_id = $wpdb->insert_id;
330
  } else {
331
+ $question_id = intval( $data['ID'] );
332
+ $results = $wpdb->update(
333
  $wpdb->prefix . 'mlw_questions',
334
  $values,
335
  array( 'question_id' => $question_id ),
347
  /**
348
  * Process Question Categories
349
  */
350
+ $question_terms_table = $wpdb->prefix . 'mlw_question_terms';
351
+ $wpdb->delete(
352
+ $question_terms_table,
353
+ array(
354
+ 'question_id' => $question_id,
355
+ 'taxonomy' => 'qsm_category',
356
+ )
357
+ );
358
+ if ( ! empty( $data['multicategories'] ) ) {
359
  foreach ( $data['multicategories'] as $term_id ) {
360
  $term_rel_data = array(
361
  'question_id' => $question_id,
362
+ 'quiz_id' => intval( $data['quiz_id'] ),
363
  'term_id' => $term_id,
364
  'taxonomy' => 'qsm_category',
365
  );
366
+ $wpdb->insert( $question_terms_table, $term_rel_data );
367
  }
368
  }
369
 
375
  *
376
  * sanitizes answers
377
  *
378
+ * @since 7.3.5
379
+ * @param array $answers The answers for the question.
380
  * @return array sanitized $answers The answers for the question.
381
  */
382
  public static function sanitize_answers( $answers, $settings ) {
383
 
384
  foreach ( $answers as $key => $answer ) {
385
  if ( 'rich' == $settings['answerEditor'] ) {
386
+ $answer[0] = wp_kses_post( $answer[0] );
387
  } else {
388
+ $answer[0] = sanitize_text_field( $answer[0] );
 
 
 
 
 
 
 
 
389
  }
390
+ $answers[ $key ] = $answer;
391
  }
392
 
393
  return $answers;
396
  /**
397
  * Get categories for a quiz
398
  *
399
+ * @since 7.2.1
400
+ * @param int $quiz_id The ID of the quiz.
401
  * @return array The array of categories.
402
  */
403
  public static function get_quiz_categories( $quiz_id = 0 ) {
404
  global $wpdb;
405
  $categories = array();
406
  if ( 0 !== $quiz_id ) {
407
+ $questions = self::load_questions_by_pages( $quiz_id );
408
+ $question_ids = array_column( $questions, 'question_id' );
409
+ $question_ids = implode( ',', $question_ids );
410
+ $question_terms = $wpdb->get_results( "SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id` IN ({$question_ids}) AND `taxonomy`='qsm_category'", ARRAY_A );
411
+ $term_ids = ! empty( $question_terms ) ? array_unique( array_column( $question_terms, 'term_id' ) ) : array();
412
+ $cat_array = self::get_question_categories_from_quiz_id( $quiz_id );
413
+ $enabled = get_option( 'qsm_multiple_category_enabled' );
 
414
  if ( $enabled && 'cancelled' !== $enabled && ! empty( $cat_array ) ) {
415
  $term_ids = array_unique( array_merge( $term_ids, $cat_array ) );
416
  }
423
  /**
424
  * Get categories from quiz id
425
  *
426
+ * @since 7.3.3
427
+ * @param int $quiz_id The ID of the quiz.
428
  * @return array The array of categories.
429
  */
430
  public static function get_question_categories_from_quiz_id( $quiz_id ) {
443
  /**
444
  * Get categories from term ids
445
  *
446
+ * @since 7.3.3
447
+ * @param int $term_ids Term IDs of the quiz.
448
  * @return array The array of categories.
449
  */
450
  public static function get_question_categories_from_term_ids( $term_ids ) {
451
  $categories = array();
452
  if ( ! empty( $term_ids ) ) {
453
+ $categories_names = array();
454
+ $categories_tree = array();
455
+ $terms = get_terms(
456
+ array(
457
+ 'taxonomy' => 'qsm_category',
458
+ 'include' => $term_ids,
459
+ 'hide_empty' => false,
460
+ 'orderby' => '',
461
+ 'order' => '',
462
+ )
463
+ );
464
  if ( ! empty( $terms ) ) {
465
  foreach ( $terms as $tax ) {
466
  $categories_names[ $tax->term_id ] = $tax->name;
479
  /**
480
  * Get categories for a Question
481
  *
482
+ * @since 7.2.1
483
+ * @param int $quiz_id The ID of the quiz.
484
  * @return array The array of categories.
485
  */
486
  public static function get_question_categories( $question_id = 0 ) {
487
  global $wpdb;
488
+ $categories_tree = array();
489
+ $categories_names = array();
490
  if ( 0 !== $question_id ) {
491
  $question_terms = $wpdb->get_results( "SELECT `term_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `question_id`='{$question_id}' AND `taxonomy`='qsm_category'", ARRAY_A );
492
  if ( ! empty( $question_terms ) ) {
493
  $term_ids = array_unique( array_column( $question_terms, 'term_id' ) );
494
  if ( ! empty( $term_ids ) ) {
495
+ $terms = get_terms(
496
+ array(
497
+ 'taxonomy' => 'qsm_category',
498
+ 'include' => array_unique( $term_ids ),
499
+ 'hide_empty' => false,
500
+ 'orderby' => '',
501
+ 'order' => '',
502
+ )
503
+ );
504
  if ( ! empty( $terms ) ) {
505
  foreach ( $terms as $tax ) {
506
  $categories_names[ $tax->term_id ] = $tax->name;
513
  }
514
  }
515
  return array(
516
+ 'category_name' => $categories_names,
517
+ 'category_tree' => $categories_tree,
518
  );
519
  }
520
  /**
php/question-types.php CHANGED
@@ -9,7 +9,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_multiple_choice' );
9
  * Registers the multiple choice type
10
  *
11
  * @return void
12
- * @since 4.4.0
13
  */
14
  function qmn_question_type_multiple_choice() {
15
  global $mlwQuizMasterNext;
@@ -21,7 +21,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_file_upload' );
21
  * Registers the file upload type
22
  *
23
  * @return void
24
- * @since 6.3.7
25
  */
26
  function qmn_question_type_file_upload() {
27
  global $mlwQuizMasterNext;
@@ -31,7 +31,7 @@ function qmn_question_type_file_upload() {
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
  *
@@ -43,7 +43,8 @@ function qmn_file_upload_display( $id, $question, $answers ) {
43
  if ( 0 == $required ) {
44
  $mlw_require_class = 'mlwRequiredFileUpload';
45
  } else {
46
- $mlw_require_class = '';}
 
47
  // $question_title = apply_filters('the_content', $question);
48
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
49
  qsm_question_title_func( $question, '', $new_question_title, $id );
@@ -52,8 +53,9 @@ function qmn_file_upload_display( $id, $question, $answers ) {
52
  <div style="display: none;" class="remove-uploaded-file"><span class="dashicons dashicons-trash"></span></div>
53
  <input class="mlw_file_upload_hidden_value" type="hidden" name="question<?php echo esc_attr( $id ); ?>" value="" />
54
  <span style="display: none;" class='mlw-file-upload-error-msg'></span>
55
- <input class="mlw_file_upload_hidden_path" type="hidden" value="" /> <?php
56
- echo apply_filters( 'qmn_file_upload_display_front', '', $id, $question, $answers );
 
57
  }
58
 
59
  /**
@@ -63,7 +65,7 @@ function qmn_file_upload_display( $id, $question, $answers ) {
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 5.3.7
67
  */
68
  function qmn_file_upload_review( $id, $question, $answers ) {
69
  $return_array = array(
@@ -116,35 +118,58 @@ function qmn_multiple_choice_display( $id, $question, $answers ) {
116
  }
117
  // $question_title = apply_filters('the_content', $question);
118
  qsm_question_title_func( $question, 'multiple_choice', $new_question_title, $id );
119
- ?> <div class='qmn_radio_answers <?php echo esc_attr( $mlw_require_class ); ?>'> <?php
120
- if ( is_array( $answers ) ) {
121
- $mlw_answer_total = 0;
122
- foreach ( $answers as $answer_index => $answer ) {
123
- $mlw_answer_total++;
124
- if ( '' !== $answer[0] ) {
125
- $answer_class = apply_filters('qsm_answer_wrapper_class', '', $answer, $id);
126
- if ( 'rich' === $answerEditor ) {
127
- ?> <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 ); ?>'> <?php
128
- } elseif ( 'image' === $answerEditor ) {
129
- ?> <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 ); ?>'> <?php
130
- } else {
131
- ?> <div class="qmn_mc_answer_wrap <?php echo esc_attr( $answer_class ); ?>" id="<?php echo esc_attr( 'question' . $id . '-' . str_replace( ' ', '-', $answer[0] ) ); ?> "> <?php
132
- }
133
- ?> <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] ); ?>" /> <label for="<?php echo esc_attr( 'question'. $id . '_' . $mlw_answer_total ); ?>"> <?php
134
- if ( 'image' === $answerEditor ) {
135
- ?> <img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" />
136
- <span class="qsm_image_caption"><?php echo esc_html( trim( htmlspecialchars_decode( $answer[3], ENT_QUOTES ) ) ); ?></span><?php
137
- } else {
138
- echo wp_kses( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ), wp_kses_allowed_html( 'post' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
- ?> </label> <?php
141
- echo apply_filters( 'qsm_multiple_choice_display_loop', ' ', $id, $question, $answers );
142
- ?> </div> <?php
143
  }
 
 
 
144
  }
145
- ?> <input type="radio" style="display: none;" name="<?php echo esc_attr( 'question' . $id ) ; ?>" id="<?php echo esc_attr( 'question' . $id . '_none' ); ?>" checked="checked" value="" /> <?php
146
- }
147
- ?> </div> <?php
148
  echo apply_filters( 'qmn_multiple_choice_display_front', '', $id, $question, $answers );
149
  }
150
 
@@ -155,7 +180,7 @@ function qmn_multiple_choice_display( $id, $question, $answers ) {
155
  * @params $question The question that is being edited.
156
  * @params @answers The array that contains the answers to the question.
157
  * @return $return_array Returns the graded question to the results page
158
- * @since 4.4.0
159
  */
160
  function qmn_multiple_choice_review( $id, $question, $answers ) {
161
  global $mlwQuizMasterNext;
@@ -177,7 +202,7 @@ function qmn_multiple_choice_review( $id, $question, $answers ) {
177
  $correct_text = array();
178
  foreach ( $answers as $answer ) {
179
  if ( 'rich' === $answerEditor ) {
180
- $answer_option = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
181
  $sinel_answer_cmp = preg_replace( "/\s+|\n+|\r/", ' ', htmlentities( $answer_option ) );
182
  if ( $rich_text_comapre == $sinel_answer_cmp ) {
183
  $return_array['points'] = $answer[1];
@@ -187,7 +212,7 @@ function qmn_multiple_choice_review( $id, $question, $answers ) {
187
  }
188
  }
189
  if ( 1 == $answer[2] ) {
190
- $correct_text[] = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
191
  }
192
  } else {
193
  $mlw_user_answer = '';
@@ -196,7 +221,7 @@ function qmn_multiple_choice_review( $id, $question, $answers ) {
196
  $mlw_user_answer = trim( htmlspecialchars_decode( $mlw_user_answer, ENT_QUOTES ) );
197
  $mlw_user_answer = str_replace( '\\', '', $mlw_user_answer );
198
  }
199
- $single_answer = trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
200
  $single_answer = str_replace( '\\', '', $single_answer );
201
  if ( $mlw_user_answer == $single_answer ) {
202
  $return_array['points'] = $answer[1];
@@ -206,7 +231,7 @@ function qmn_multiple_choice_review( $id, $question, $answers ) {
206
  }
207
  }
208
  if ( 1 == $answer[2] ) {
209
- $correct_text[] = stripslashes( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
210
  }
211
  }
212
  }
@@ -222,7 +247,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_date' );
222
  * Registers the date type
223
  *
224
  * @return void
225
- * @since 6.3.7
226
  */
227
  function qmn_question_type_date() {
228
  global $mlwQuizMasterNext;
@@ -244,10 +269,13 @@ function qmn_date_display( $id, $question, $answers ) {
244
  if ( 0 == $required ) {
245
  $mlw_require_class = 'mlwRequiredDate';
246
  } else {
247
- $mlw_require_class = '';}
 
248
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
249
  qsm_question_title_func( $question, '', $new_question_title, $id );
250
- ?> <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="" /> <?php
 
 
251
  echo apply_filters( 'qmn_date_display_front', '', $id, $question, $answers );
252
  }
253
 
@@ -258,7 +286,7 @@ function qmn_date_display( $id, $question, $answers ) {
258
  * @params $question The question that is being edited.
259
  * @params @answers The array that contains the answers to the question.
260
  * @return $return_array Returns the graded question to the results page
261
- * @since 6.3.7
262
  */
263
  function qmn_date_review( $id, $question, $answers ) {
264
  $return_array = array(
@@ -268,8 +296,8 @@ function qmn_date_review( $id, $question, $answers ) {
268
  'correct_text' => '',
269
  );
270
  if ( isset( $_POST[ 'question' . $id ] ) ) {
271
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
272
- $decode_user_answer = htmlspecialchars_decode( $question_input , ENT_QUOTES );
273
  $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
274
  } else {
275
  $mlw_user_answer = ' ';
@@ -296,7 +324,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_choice' );
296
  * This function registers the horizontal multiple choice type.
297
  *
298
  * @return void
299
- * @since 4.4.0
300
  */
301
  function qmn_question_type_horizontal_multiple_choice() {
302
  global $mlwQuizMasterNext;
@@ -324,29 +352,43 @@ function qmn_horizontal_multiple_choice_display( $id, $question, $answers ) {
324
  // $question_title = apply_filters('the_content', $question);
325
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
326
  qsm_question_title_func( $question, 'horizontal_multiple_choice', $new_question_title, $id );
327
- ?> <div class="qmn_radio_answers qmn_radio_horizontal_answers <?php echo esc_attr( $mlw_require_class ); ?>"> <?php
328
- if ( is_array( $answers ) ) {
329
- $mlw_answer_total = 0;
330
- foreach ( $answers as $answer_index => $answer ) {
331
- $mlw_answer_total++;
332
- if ( '' !== $answer[0] ) {
333
- $answer_class = apply_filters('qsm_answer_wrapper_class', '', $answer, $id);
334
- ?> <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] ); ?>" /><label for="question<?php echo esc_attr( $id ). '_' .esc_attr( $mlw_answer_total ); ?>"><?php
335
- if ( 'image' === $answerEditor ) {
336
- ?> <img alt="<?php echo esc_attr( $new_question_title ); ?>" src=" <?php esc_url_e( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" /> <?php
337
- } else {
338
- echo wp_kses( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ), wp_kses_allowed_html( 'post' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  }
340
- ?> </label> <?php
341
- echo apply_filters( 'qsm_multiple_choice_horizontal_display_loop', '', $id, $question, $answers );
342
- ?> </span> <?php
343
  }
 
 
 
 
344
  }
345
- echo apply_filters( 'qmn_horizontal_multiple_choice_question_display', '', $id, $question, $answers );
346
- ?> <input type="radio" style="display: none;" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ); ?>_none" checked="checked" value="" /> <?php
347
- }
348
- ?> </div> <?php
349
-
350
  echo apply_filters( 'qmn_horizontal_multiple_choice_display_front', '', $id, $question, $answers );
351
  }
352
 
@@ -357,7 +399,7 @@ function qmn_horizontal_multiple_choice_display( $id, $question, $answers ) {
357
  * @params $question The question that is being edited.
358
  * @params @answers The array that contains the answers to the question.
359
  * @return $return_array Returns the graded question to the results page
360
- * @since 4.4.0
361
  */
362
  function qmn_horizontal_multiple_choice_review( $id, $question, $answers ) {
363
  global $mlwQuizMasterNext;
@@ -424,7 +466,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_drop_down' );
424
  * This function registers the drop down question type
425
  *
426
  * @return void
427
- * @since 4.4.0
428
  */
429
  function qmn_question_type_drop_down() {
430
  global $mlwQuizMasterNext;
@@ -451,17 +493,23 @@ function qmn_drop_down_display( $id, $question, $answers ) {
451
  // $question_title = apply_filters('the_content', $question);
452
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
453
  qsm_question_title_func( $question, '', $new_question_title, $id );
454
- ?><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><?php
455
- if ( is_array( $answers ) ) {
456
- $mlw_answer_total = 0;
457
- foreach ( $answers as $answer ) {
458
- $mlw_answer_total++;
459
- if ( '' !== $answer[0] ) {
460
- ?><option value="<?php echo esc_attr( $answer[0] ); ?>"><?php echo esc_html( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ); ?></option><?php
 
 
 
 
 
461
  }
462
  }
463
- }
464
- ?> </select> <?php
 
465
  echo apply_filters( 'qmn_drop_down_display_front', '', $id, $question, $answers );
466
  }
467
 
@@ -472,7 +520,7 @@ function qmn_drop_down_display( $id, $question, $answers ) {
472
  * @params $question The question that is being edited.
473
  * @params @answers The array that contains the answers to the question.
474
  * @return $return_array Returns the graded question to the results page
475
- * @since 4.4.0
476
  */
477
  function qmn_drop_down_review( $id, $question, $answers ) {
478
  global $mlwQuizMasterNext;
@@ -514,7 +562,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_small_open' );
514
  * This function registers the small open question type
515
  *
516
  * @return void
517
- * @since 4.4.0
518
  */
519
  function qmn_question_type_small_open() {
520
  global $mlwQuizMasterNext;
@@ -540,11 +588,14 @@ function qmn_small_open_display( $id, $question, $answers ) {
540
  if ( 0 == $required ) {
541
  $mlw_require_class = 'mlwRequiredText';
542
  } else {
543
- $mlw_require_class = '';}
 
544
  // $question_title = apply_filters('the_content', $question);
545
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
546
  qsm_question_title_func( $question, '', $new_question_title, $id );
547
- ?><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 ); ?>" /><?php
 
 
548
  echo apply_filters( 'qmn_small_open_display_front', '', $id, $question, $answers );
549
  }
550
 
@@ -555,7 +606,7 @@ function qmn_small_open_display( $id, $question, $answers ) {
555
  * @params $question The question that is being edited.
556
  * @params @answers The array that contains the answers to the question.
557
  * @return $return_array Returns the graded question to the results page
558
- * @since 4.4.0
559
  */
560
  function qmn_small_open_review( $id, $question, $answers ) {
561
  $return_array = array(
@@ -565,7 +616,7 @@ function qmn_small_open_review( $id, $question, $answers ) {
565
  'correct_text' => '',
566
  );
567
  if ( isset( $_POST[ 'question' . $id ] ) ) {
568
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
569
  $decode_user_answer = htmlspecialchars_decode( $question_input, ENT_QUOTES );
570
  $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
571
  } else {
@@ -593,7 +644,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_multiple_response' );
593
  * This function registers the multiple response question type
594
  *
595
  * @return void
596
- * @since 4.4.0
597
  */
598
  function qmn_question_type_multiple_response() {
599
  global $mlwQuizMasterNext;
@@ -620,31 +671,41 @@ function qmn_multiple_response_display( $id, $question, $answers ) {
620
  if ( 0 == $required ) {
621
  $mlw_require_class = 'mlwRequiredCheck';
622
  } else {
623
- $mlw_require_class = '';}
624
- // $question_title = apply_filters('the_content', $question);
625
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
626
  $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
627
  qsm_question_title_func( $question, '', $new_question_title, $id );
628
- ?><div class="qmn_check_answers <?php echo esc_attr( $mlw_require_class ); ?>"><?php
629
- if ( is_array( $answers ) ) {
630
- $mlw_answer_total = 0;
631
- foreach ( $answers as $answer ) {
632
- $mlw_answer_total++;
633
- if ( '' !== $answer[0] ) {
634
- ?><div class="qsm_check_answer">
635
- <input type="hidden" name="question<?php echo esc_attr( $id ); ?>" value="This value does not matter" />
636
- <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 ); ?>"><?php
637
- if ( 'image' === $answerEditor ) {
638
- ?><img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php esc_url_e( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" /><?php
639
- } else {
640
- echo wp_kses( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ), wp_kses_allowed_html( 'post' ) );
 
 
 
 
 
 
 
 
 
 
 
641
  }
642
- ?></label>
643
- </div><?php
644
  }
645
  }
646
- }
647
- ?></div><?php
 
648
  echo apply_filters( 'qmn_multiple_response_display_front', '', $id, $question, $answers );
649
  }
650
 
@@ -655,7 +716,7 @@ function qmn_multiple_response_display( $id, $question, $answers ) {
655
  * @params $question The question that is being edited.
656
  * @params @answers The array that contains the answers to the question.
657
  * @return $return_array Returns the graded question to the results page
658
- * @since 4.4.0
659
  */
660
  function qmn_multiple_response_review( $id, $question, $answers ) {
661
  $return_array = array(
@@ -693,7 +754,7 @@ function qmn_multiple_response_review( $id, $question, $answers ) {
693
  $return_array['correct_text'] = implode( '.', $correct_text );
694
  /**
695
  * Hook to filter answers array
696
- */
697
  return apply_filters( 'qmn_multiple_response_review', $return_array, $answers );
698
  }
699
 
@@ -725,12 +786,15 @@ function qmn_large_open_display( $id, $question, $answers ) {
725
  if ( 0 == $required ) {
726
  $mlw_require_class = 'mlwRequiredText';
727
  } else {
728
- $mlw_require_class = '';}
 
729
  $limit_text_att = $limit_text ? "maxlength='" . $limit_text . "' " : '';
730
  // $question_title = apply_filters('the_content', $question);
731
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
732
  qsm_question_title_func( $question, '', $new_question_title, $id );
733
- ?><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><?php
 
 
734
  echo apply_filters( 'qmn_large_open_display_front', '', $id, $question, $answers );
735
  }
736
 
@@ -741,7 +805,7 @@ function qmn_large_open_display( $id, $question, $answers ) {
741
  * @params $question The question that is being edited.
742
  * @params @answers The array that contains the answers to the question.
743
  * @return $return_array Returns the graded question to the results page
744
- * @since 4.4.0
745
  */
746
  function qmn_large_open_review( $id, $question, $answers ) {
747
  $return_array = array(
@@ -751,7 +815,7 @@ function qmn_large_open_review( $id, $question, $answers ) {
751
  'correct_text' => '',
752
  );
753
  if ( isset( $_POST[ 'question' . $id ] ) ) {
754
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
755
  $decode_user_answer = strval( htmlspecialchars_decode( $question_input, ENT_QUOTES ) );
756
  $mlw_user_answer = trim( str_replace( ' ', '', preg_replace( '/\s\s+/', '', $decode_user_answer ) ) );
757
  } else {
@@ -779,7 +843,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_text_block' );
779
  * This function registers the text block question type
780
  *
781
  * @return void
782
- * @since 4.4.0
783
  */
784
  function qmn_question_type_text_block() {
785
  global $mlwQuizMasterNext;
@@ -804,7 +868,7 @@ function qmn_question_type_text_block() {
804
  * @since 4.4.0
805
  */
806
  function qmn_text_block_display( $id, $question, $answers ) {
807
- echo wp_kses ( do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ), wp_kses_allowed_html( 'post' ) );
808
  }
809
 
810
  add_action( 'plugins_loaded', 'qmn_question_type_number' );
@@ -816,7 +880,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_number' );
816
  * @params $question The question that is being edited.
817
  * @params @answers The array that contains the answers to the question.
818
  * @return void
819
- * @since 4.4.0
820
  */
821
  function qmn_question_type_number() {
822
  global $mlwQuizMasterNext;
@@ -840,11 +904,14 @@ function qmn_number_display( $id, $question, $answers ) {
840
  if ( 0 == $required ) {
841
  $mlw_require_class = 'mlwRequiredNumber';
842
  } else {
843
- $mlw_require_class = '';}
 
844
  // $question_title = apply_filters('the_content', $question);
845
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
846
  qsm_question_title_func( $question, '', $new_question_title, $id );
847
- ?><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 ); ?>" /><?php
 
 
848
  echo apply_filters( 'qmn_number_display_front', '', $id, $question, $answers );
849
  }
850
 
@@ -855,7 +922,7 @@ function qmn_number_display( $id, $question, $answers ) {
855
  * @params $question The question that is being edited.
856
  * @params @answers The array that contains the answers to the question.
857
  * @return $return_array Returns the graded question to the results page
858
- * @since 4.4.0
859
  */
860
  function qmn_number_review( $id, $question, $answers ) {
861
  $return_array = array(
@@ -865,7 +932,7 @@ function qmn_number_review( $id, $question, $answers ) {
865
  'correct_text' => '',
866
  );
867
  if ( isset( $_POST[ 'question' . $id ] ) ) {
868
- $question_input = sanitize_textarea_field( wp_unslash( $_POST[ 'question' . $id ] ) );
869
  $mlw_user_answer = htmlspecialchars_decode( $question_input, ENT_QUOTES );
870
  } else {
871
  $mlw_user_answer = ' ';
@@ -891,7 +958,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_accept' );
891
  * This function registers the accept question type.
892
  *
893
  * @return void Description
894
- * @since 4.4.0
895
  */
896
  function qmn_question_type_accept() {
897
  global $mlwQuizMasterNext;
@@ -922,11 +989,14 @@ function qmn_accept_display( $id, $question, $answers ) {
922
  if ( 0 == $required ) {
923
  $mlw_require_class = 'mlwRequiredAccept';
924
  } else {
925
- $mlw_require_class = '';}
926
- ?><div class="qmn_accept_answers">
 
 
927
  <input type="checkbox" id="mlwAcceptance" class="<?php echo esc_attr( $mlw_require_class ); ?>" />
928
- <label for="mlwAcceptance"><span class="qmn_accept_text"><?php echo wp_kses( do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ), wp_kses_allowed_html( 'post' ) ); ?></span></label>
929
- </div><?php
 
930
  echo apply_filters( 'qmn_accept_display_front', '', $id, $question, $answers );
931
  }
932
 
@@ -971,13 +1041,14 @@ function qmn_captcha_display( $id, $question, $answers ) {
971
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
972
  ?>
973
  <span class="mlw_qmn_question">
974
- <?php qsm_question_title_func( $question, '', $new_question_title, $id ); ?>
975
  </span>
976
  <div class="mlw_captchaWrap">
977
  <canvas alt="" id="mlw_captcha" class="mlw_captcha" width="100" height="50"></canvas>
978
  </div>
979
  <input type="text" class="mlw_answer_open_text <?php echo esc_attr( $mlw_require_class ); ?>" id="mlw_captcha_text" name="mlw_user_captcha"/>
980
- <input type="hidden" name="mlw_code_captcha" id="mlw_code_captcha" value="none" /><?php
 
981
  echo apply_filters( 'qmn_captcha_display_front', '', $id, $question, $answers );
982
  }
983
 
@@ -987,7 +1058,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_horizontal_multiple_response' )
987
  * This function registers the horizontal multiple response question
988
  *
989
  * @return void
990
- * @since 4.4.0
991
  */
992
  function qmn_question_type_horizontal_multiple_response() {
993
  global $mlwQuizMasterNext;
@@ -1009,7 +1080,8 @@ function qmn_horizontal_multiple_response_display( $id, $question, $answers ) {
1009
  if ( 0 == $required ) {
1010
  $mlw_require_class = 'mlwRequiredCheck';
1011
  } else {
1012
- $mlw_require_class = '';}
 
1013
  // $question_title = apply_filters('the_content', $question);
1014
  $limit_multiple_response = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'limit_multiple_response' );
1015
  $limit_mr_text = '';
@@ -1019,24 +1091,36 @@ function qmn_horizontal_multiple_response_display( $id, $question, $answers ) {
1019
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
1020
  $answerEditor = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'answerEditor' );
1021
  qsm_question_title_func( $question, '', $new_question_title, $id );
1022
- ?><div class="qmn_check_answers qmn_multiple_horizontal_check <?php echo esc_attr( $mlw_require_class ); ?>"><?php
1023
- if ( is_array( $answers ) ) {
1024
- $mlw_answer_total = 0;
1025
- foreach ( $answers as $answer ) {
1026
- $mlw_answer_total++;
1027
- if ( '' !== $answer[0] ) {
1028
- ?><input type="hidden" name="question<?php echo esc_attr( $id ); ?> " value="This value does not matter" />
1029
- <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] ); ?>" /> <label for="question<?php echo esc_attr( $id ). '_' . esc_attr( $mlw_answer_total ); ?>"><?php
1030
- if ( 'image' === $answerEditor ) {
1031
- ?><img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php esc_url_e( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ); ?>" /><?php
1032
- } else {
1033
- echo wp_kses( trim( do_shortcode( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) ), wp_kses_allowed_html( 'post' ) );
 
 
 
 
 
 
 
 
 
 
 
 
1034
  }
1035
- ?></label></span><?php
1036
  }
1037
  }
1038
- }
1039
- ?></div><?php
 
1040
  echo apply_filters( 'qmn_horizontal_multiple_response_display_front', '', $id, $question, $answers );
1041
  }
1042
 
@@ -1047,7 +1131,7 @@ function qmn_horizontal_multiple_response_display( $id, $question, $answers ) {
1047
  * @params $question The question that is being edited.
1048
  * @params @answers The array that contains the answers to the question.
1049
  * @return $return_array Returns the graded question to the Results page
1050
- * @since 4.4.0
1051
  */
1052
  function qmn_horizontal_multiple_response_review( $id, $question, $answers ) {
1053
  $return_array = array(
@@ -1095,7 +1179,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_fill_blank' );
1095
  * This function registers the fill in the blank question type
1096
  *
1097
  * @return void
1098
- * @since 4.4.0
1099
  */
1100
  function qmn_question_type_fill_blank() {
1101
  global $mlwQuizMasterNext;
@@ -1124,7 +1208,7 @@ function qmn_question_type_fill_blank() {
1124
  * @params $id The ID of the multiple choice question
1125
  * @params $question The question that is being edited.
1126
  * @params @answers The array that contains the answers to the question.
1127
- * @since 4.4.0
1128
  */
1129
  function qmn_fill_blank_display( $id, $question, $answers ) {
1130
  global $mlwQuizMasterNext;
@@ -1155,7 +1239,7 @@ function qmn_fill_blank_display( $id, $question, $answers ) {
1155
  * @params $question The question that is being edited.
1156
  * @params @answers The array that contains the answers to the question.
1157
  * @return $return_array Returns the graded question to the results page
1158
- * @since 4.4.0
1159
  */
1160
  function qmn_fill_blank_review( $id, $question, $answers ) {
1161
  global $mlwQuizMasterNext;
@@ -1171,13 +1255,15 @@ function qmn_fill_blank_review( $id, $question, $answers ) {
1171
  $return_array['question_text'] = str_replace( array( '%BLANK%', '%blank%' ), array( '__________', '__________' ), do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
1172
  }
1173
  $correct_text = $user_input = $user_text = array();
 
1174
  if ( isset( $_POST[ 'question' . $id ] ) && ! empty( $_POST[ 'question' . $id ] ) ) {
1175
  $question_input = array_map( 'sanitize_textarea_field', wp_unslash( $_POST[ 'question' . $id ] ) );
 
1176
  foreach ( $question_input as $input ) {
1177
  $decode_user_answer = strval( stripslashes( htmlspecialchars_decode( $input, ENT_QUOTES ) ) );
1178
  $mlw_user_answer = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_answer ) ) );
1179
- $user_input[] = mb_strtoupper( $mlw_user_answer );
1180
- $user_text[] = $mlw_user_answer;
1181
  }
1182
  }
1183
 
@@ -1186,29 +1272,33 @@ function qmn_fill_blank_review( $id, $question, $answers ) {
1186
  foreach ( $answers as $key => $answer ) {
1187
  $decode_user_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
1188
  $decode_user_text = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_text ) ) );
 
1189
  if ( mb_strtoupper( $decode_user_text ) == $user_input[ $key ] ) {
1190
  $return_array['points'] += $answer[1];
1191
- $user_correct += 1;
1192
  }
1193
  $total_correct++;
1194
  $correct_text[] = $answers[ $key ][0];
1195
  }
1196
- $return_array['correct_text'] = implode( '.', $correct_text );
1197
- $return_array['user_text'] = implode( '.', $user_text );
 
 
1198
  $return_array['user_compare_text'] = implode( '=====', $user_text );
 
1199
  if ( $total_correct == $user_correct ) {
1200
- $return_array['correct'] = 'correct';
1201
  }
1202
  } else {
1203
  $answers_array = array();
1204
- $correct = true;
1205
  foreach ( $answers as $answer ) {
1206
  $decode_user_text = strval( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) );
1207
  $decode_user_text = trim( preg_replace( '/\s\s+/', ' ', str_replace( "\n", ' ', $decode_user_text ) ) );
1208
- $answers_array[] = mb_strtoupper( $decode_user_text );
1209
  }
1210
- $total_user_input = sizeof($user_input);
1211
- $total_option = sizeof($answers);
1212
  if ( $total_user_input < $total_option ) {
1213
  foreach ( $user_input as $k => $input ) {
1214
  $key = array_search( $input, $answers_array, true );
@@ -1231,10 +1321,10 @@ function qmn_fill_blank_review( $id, $question, $answers ) {
1231
  }
1232
  }
1233
  if ( $correct ) {
1234
- $return_array['correct'] = 'correct';
1235
  }
1236
- $return_array['user_text'] = implode( '.', $user_text );
1237
- $return_array['correct_text'] = implode( '.', $correct_text );
1238
  $return_array['user_compare_text'] = implode( '=====', $user_text );
1239
  }
1240
 
@@ -1252,7 +1342,7 @@ add_action( 'plugins_loaded', 'qmn_question_type_polar' );
1252
  * This function registers the fill in the blank question type
1253
  *
1254
  * @return void
1255
- * @since 6.4.1
1256
  */
1257
  function qmn_question_type_polar() {
1258
  global $mlwQuizMasterNext;
@@ -1265,7 +1355,7 @@ function qmn_question_type_polar() {
1265
  * @params $id The ID of the multiple choice question
1266
  * @params $question The question that is being edited.
1267
  * @params @answers The array that contains the answers to the question.
1268
- * @since 6.4.1
1269
  */
1270
  function qmn_polar_display( $id, $question, $answers ) {
1271
  global $mlwQuizMasterNext;
@@ -1280,18 +1370,18 @@ function qmn_polar_display( $id, $question, $answers ) {
1280
  $is_reverse = false;
1281
  $check_point = $second_point;
1282
  if ( $first_point > $second_point ) {
1283
- $is_reverse = true;
1284
- $check_point = $first_point;
1285
  }
1286
- $total_answer = count( $answers );
1287
- $id = esc_attr( intval( $id ) );
1288
- $answar1 = $first_point;
1289
- $answar2 = $second_point;
1290
- $slider_data_atts = '';
1291
- $slider_data_atts .= ' data-answer1='.$answar1.' ';
1292
- $slider_data_atts .= ' data-answer2='.$answar2.' ';
1293
- $slider_data_atts .= ' data-is_reverse='.intval($is_reverse).' ';
1294
- $slider_data_atts .= ' data-is_required='.$required .' ';
1295
  if ( 0 == $required ) {
1296
  $mlw_require_class = 'mlwRequiredText';
1297
  } else {
@@ -1302,12 +1392,12 @@ function qmn_polar_display( $id, $question, $answers ) {
1302
 
1303
  ?>
1304
  <span class="mlw_qmn_question question-type-polar-s">
1305
- <div class='left-polar-title'> <?php echo esc_html($answers[0][0]); ?> </div>
1306
  <div class='slider-main-wrapper'>
1307
- <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=''/>
1308
- <div id="slider-<?php echo esc_attr($id);?>" <?php echo esc_attr($slider_data_atts);?> ></div>
1309
  </div>
1310
- <div class='right-polar-title'><?php echo esc_html($answers[1][0]); ?></div>
1311
  </span>
1312
  <?php
1313
 
@@ -1320,7 +1410,7 @@ function qmn_polar_display( $id, $question, $answers ) {
1320
  * @params $question The question that is being edited.
1321
  * @params @answers The array that contains the answers to the question.
1322
  * @return $return_array Returns the graded question to the results page
1323
- * @since 6.4.1
1324
  */
1325
  function qmn_polar_review( $id, $question, $answers ) {
1326
  $return_array = array(
@@ -1350,7 +1440,7 @@ function qmn_polar_review( $id, $question, $answers ) {
1350
  }
1351
  /**
1352
  * Hook to filter answers array
1353
- */
1354
  return apply_filters( 'qmn_polar_review', $return_array, $answers );
1355
  }
1356
 
@@ -1373,18 +1463,22 @@ function qsm_question_title_func( $question, $question_type = '', $new_question_
1373
  if ( $question_id ) {
1374
  $featureImageID = $mlwQuizMasterNext->pluginHelper->get_question_setting( $question_id, 'featureImageID' );
1375
  if ( $featureImageID ) {
1376
- ?> <div class="qsm-featured-image"><?php echo wp_get_attachment_image( $featureImageID, apply_filters( 'qsm_filter_feature_image_size', 'full', $question_id ) ) ; ?></div><?php
 
 
1377
  }
1378
  }
1379
  if ( '' !== $new_question_title ) {
1380
- ?><div class='mlw_qmn_new_question'><?php echo esc_html( htmlspecialchars_decode( $new_question_title, ENT_QUOTES ) );?> </div><?php
 
 
1381
  $polar_extra_class .= ' qsm_remove_bold';
1382
  }
1383
 
1384
  ?>
1385
  <div class='mlw_qmn_question <?php echo esc_attr( $polar_extra_class ); ?>' >
1386
- <?php echo do_shortcode( htmlspecialchars_decode( $question_title, ENT_QUOTES ). $deselect_answer );?>
1387
  </div>
1388
  <?php
1389
  }
1390
- ?>
9
  * Registers the multiple choice type
10
  *
11
  * @return void
12
+ * @since 4.4.0
13
  */
14
  function qmn_question_type_multiple_choice() {
15
  global $mlwQuizMasterNext;
21
  * Registers the file upload type
22
  *
23
  * @return void
24
+ * @since 6.3.7
25
  */
26
  function qmn_question_type_file_upload() {
27
  global $mlwQuizMasterNext;
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
  *
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 );
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
  /**
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(
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
 
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;
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];
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 = '';
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];
231
  }
232
  }
233
  if ( 1 == $answer[2] ) {
234
+ $correct_text[] = stripslashes( trim( htmlspecialchars_decode( $answer[0], ENT_QUOTES ) ) );
235
  }
236
  }
237
  }
247
  * Registers the date type
248
  *
249
  * @return void
250
+ * @since 6.3.7
251
  */
252
  function qmn_question_type_date() {
253
  global $mlwQuizMasterNext;
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
 
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(
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 = ' ';
324
  * This function registers the horizontal multiple choice type.
325
  *
326
  * @return void
327
+ * @since 4.4.0
328
  */
329
  function qmn_question_type_horizontal_multiple_choice() {
330
  global $mlwQuizMasterNext;
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
 
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;
466
  * This function registers the drop down question type
467
  *
468
  * @return void
469
+ * @since 4.4.0
470
  */
471
  function qmn_question_type_drop_down() {
472
  global $mlwQuizMasterNext;
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
 
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;
562
  * This function registers the small open question type
563
  *
564
  * @return void
565
+ * @since 4.4.0
566
  */
567
  function qmn_question_type_small_open() {
568
  global $mlwQuizMasterNext;
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
 
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(
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 {
644
  * This function registers the multiple response question type
645
  *
646
  * @return void
647
+ * @since 4.4.0
648
  */
649
  function qmn_question_type_multiple_response() {
650
  global $mlwQuizMasterNext;
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
 
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(
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
 
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
 
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(
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 {
843
  * This function registers the text block question type
844
  *
845
  * @return void
846
+ * @since 4.4.0
847
  */
848
  function qmn_question_type_text_block() {
849
  global $mlwQuizMasterNext;
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' );
880
  * @params $question The question that is being edited.
881
  * @params @answers The array that contains the answers to the question.
882
  * @return void
883
+ * @since 4.4.0
884
  */
885
  function qmn_question_type_number() {
886
  global $mlwQuizMasterNext;
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
 
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(
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 = ' ';
958
  * This function registers the accept question type.
959
  *
960
  * @return void Description
961
+ * @since 4.4.0
962
  */
963
  function qmn_question_type_accept() {
964
  global $mlwQuizMasterNext;
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
 
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
 
1058
  * This function registers the horizontal multiple response question
1059
  *
1060
  * @return void
1061
+ * @since 4.4.0
1062
  */
1063
  function qmn_question_type_horizontal_multiple_response() {
1064
  global $mlwQuizMasterNext;
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 = '';
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
 
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(
1179
  * This function registers the fill in the blank question type
1180
  *
1181
  * @return void
1182
+ * @since 4.4.0
1183
  */
1184
  function qmn_question_type_fill_blank() {
1185
  global $mlwQuizMasterNext;
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;
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;
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
 
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 );
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
 
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;
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;
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 {
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
 
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(
1440
  }
1441
  /**
1442
  * Hook to filter answers array
1443
+ */
1444
  return apply_filters( 'qmn_polar_review', $return_array, $answers );
1445
  }
1446
 
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
+ ?>
php/template-variables.php CHANGED
@@ -1,8 +1,4 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
  /**
7
  * This file contains all the variables that are in the plugin. It registers them and then makes them available for use.
8
  *
@@ -10,6 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) {
10
  *
11
  * @since 4.4.0
12
  */
 
 
 
 
 
13
  /*
14
  Results Array For Reference:
15
 
@@ -65,7 +66,7 @@ add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_single_quest
65
  add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_total_possible_points', 10, 2 );
66
  add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_total_attempted_questions', 10, 2 );
67
  add_filter( 'mlw_qmn_template_variable_results_page', 'mlw_qmn_variable_user_full_name', 10, 2 );
68
- add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_poll_result', 10, 3);
69
  add_filter( 'qmn_end_results', 'qsm_variable_poll_result', 10, 3 );
70
  add_filter( 'mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_quiz_name', 10, 2 );
71
  add_filter( 'mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_quiz_links', 10, 2 );
@@ -75,8 +76,9 @@ add_filter( 'mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_social_shar
75
  add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_minimum_points', 10, 2 );
76
 
77
  /**
 
 
78
  * @since 6.4.11
79
- * @since 7.1.3 Changed the display structure to new structure.
80
  * @param str $content
81
  * @param array $mlw_quiz_array
82
  * Show particular question answer.
@@ -131,8 +133,8 @@ function qsm_variable_single_question_answer( $content, $mlw_quiz_array ) {
131
  *
132
  * @since 7.0.2
133
  *
134
- * @param string $content
135
- * @param array $mlw_quiz_array
136
  * @return string $content
137
  */
138
  function qsm_variable_total_possible_points( $content, $mlw_quiz_array ) {
@@ -147,8 +149,8 @@ function qsm_variable_total_possible_points( $content, $mlw_quiz_array ) {
147
  *
148
  * @since 7.0.2
149
  *
150
- * @param string $content
151
- * @param array $mlw_quiz_array
152
  * @return string $content
153
  */
154
  function qsm_variable_total_attempted_questions( $content, $mlw_quiz_array ) {
@@ -163,7 +165,7 @@ function qsm_variable_total_attempted_questions( $content, $mlw_quiz_array ) {
163
  * @param str $content
164
  * @param arr $mlw_quiz_array
165
  */
166
- function qsm_variable_poll_result( $content, $mlw_quiz_array, $variables = "" ) {
167
  $quiz_id = is_object( $mlw_quiz_array ) ? $mlw_quiz_array->quiz_id : $mlw_quiz_array['quiz_id'];
168
  while ( false !== strpos( $content, '%POLL_RESULTS_' ) ) {
169
  $question_id = mlw_qmn_get_string_between( $content, '%POLL_RESULTS_', '%' );
@@ -176,7 +178,7 @@ function qsm_variable_poll_result( $content, $mlw_quiz_array, $variables = "" )
176
  $total_result = $total_query['total_count'];
177
  $ser_answer = $wpdb->get_row( $wpdb->prepare( "SELECT answer_array,question_settings FROM {$wpdb->prefix}mlw_questions WHERE question_id = %d", $question_id ), ARRAY_A );
178
  $ser_answer_arry = qmn_sanitize_input_data( $ser_answer['answer_array'] );
179
- $question_settings = qmn_sanitize_input_data( $ser_answer['question_settings'] );
180
  $ser_answer_arry_change = array_filter( array_merge( array( 0 ), $ser_answer_arry ) );
181
  $total_quiz_results = $wpdb->get_results( $wpdb->prepare( "SELECT quiz_results FROM {$wpdb->prefix}mlw_results WHERE quiz_id = %d", $quiz_id ), ARRAY_A );
182
  $answer_array = array();
@@ -197,8 +199,8 @@ function qsm_variable_poll_result( $content, $mlw_quiz_array, $variables = "" )
197
  if ( '' !== $answer_str && qsm_find_key_from_array( $answer_str, $ser_answer_arry_change ) ) {
198
  $percentage = number_format( $answer_count / $total_result * 100, 2 );
199
  $answer_str = qsm_answers_type_evaluated( $answer_str, $question_settings );
200
- $str .= $answer_str. ' : ' . $percentage . '%<br/>';
201
- $str .= '<progress value="' . $percentage . '" max="100">' . $percentage . ' %</progress><br/>';
202
  }
203
  }
204
  }
@@ -322,9 +324,9 @@ function mlw_qmn_variable_amount_correct( $content, $mlw_quiz_array ) {
322
  /**
323
  * Return total incorrect amount
324
  *
325
- * @since 7.0.3
326
- * @param string $content
327
- * @param array $mlw_quiz_array
328
  * @return string
329
  */
330
  function mlw_qmn_variable_amount_incorrect( $content, $mlw_quiz_array ) {
@@ -382,9 +384,9 @@ function mlw_qmn_variable_current_user( $content, $mlw_quiz_array ) {
382
  /**
383
  * Returns full name of user
384
  *
385
- * @since 7.1.11
386
- * @param string $content
387
- * @param array $mlw_quiz_array
388
  * @return string
389
  */
390
  function mlw_qmn_variable_user_full_name( $content, $mlw_quiz_array ) {
@@ -421,7 +423,7 @@ function mlw_qmn_variable_user_email( $content, $mlw_quiz_array ) {
421
  /**
422
  * Returns user value for supplied contact field
423
  *
424
- * @since 5.0.0
425
  * @return string The HTML for the content
426
  */
427
  function qsm_contact_field_variable( $content, $results_array ) {
@@ -435,7 +437,7 @@ function qsm_contact_field_variable( $content, $results_array ) {
435
  /**
436
  * Returns user values for all contact fields
437
  *
438
- * @since 5.0.0
439
  * @return string The HTML for the content
440
  */
441
  function qsm_all_contact_fields_variable( $content, $results ) {
@@ -452,7 +454,7 @@ function qsm_all_contact_fields_variable( $content, $results ) {
452
  /**
453
  * Converts the %QUESTIONS_ANSWERS% into the template
454
  *
455
- * @param string $content The content to be checked for the template
456
  * @param array $mlw_quiz_array The array for the response data
457
  */
458
  function mlw_qmn_variable_question_answers( $content, $mlw_quiz_array ) {
@@ -530,8 +532,8 @@ function mlw_qmn_variable_timer_seconds( $content, $mlw_quiz_array ) {
530
  /**
531
  * Replaces the variable %CURRENT_DATE% and displays the current date
532
  *
533
- * @param string $content The contents of the results page
534
- * @param array $results The array of all the results from user taking the quiz
535
  * @return string Returns the contents for the results page
536
  */
537
  function mlw_qmn_variable_date( $content, $results ) {
@@ -543,8 +545,8 @@ function mlw_qmn_variable_date( $content, $results ) {
543
  /**
544
  * Replaces the variable %DATE_TAKEN% and returns the date the user submitted his or her responses
545
  *
546
- * @param string $content The contents of the results page
547
- * @param array $results The array of all the results from user taking the quiz
548
  * @return string Returns the contents for the results page
549
  */
550
  function mlw_qmn_variable_date_taken( $content, $mlw_quiz_array ) {
@@ -588,7 +590,7 @@ function qmn_variable_category_points( $content, $mlw_quiz_array ) {
588
  $length++;
589
  }
590
  }
591
- if ( sizeof( $category_data['ids'] == $length ) ) {
592
  $return_points += $answer['points'];
593
  }
594
  } else {
@@ -630,11 +632,11 @@ function qmn_variable_average_category_points( $content, $mlw_quiz_array ) {
630
  foreach ( $mlw_quiz_array['question_answers_array'] as $answer ) {
631
  if ( is_array( $answer['multicategories'] ) ) {
632
  foreach ( $answer['multicategories'] as $category ) {
633
- $category_name_object = get_term_by( 'ID', $category, 'qsm_category' );
634
  $category_name_of_question = ( ! empty( $category_name_object->name ) ? $category_name_object->name : '' );
635
- if ( $category_name_object->name == $category_name && '11' !== $answer['question_type'] ) {
636
  $total_questions += 1;
637
- $return_points += $answer['points'];
638
  }
639
  }
640
  }
@@ -693,7 +695,7 @@ function qmn_variable_category_score( $content, $mlw_quiz_array ) {
693
  $length++;
694
  }
695
  }
696
- if ( sizeof( $category_data['ids'] == $length ) ) {
697
  $total_questions += 1;
698
  if ( 'correct' === $answer['correct'] ) {
699
  $amount_correct += 1;
@@ -844,18 +846,16 @@ function qsm_end_results_rank( $result_display, $qmn_quiz_options, $qmn_array_fo
844
  }
845
 
846
  /**
847
- *
848
  * Add iFrame to allowed wp_kses_post tags
849
  *
850
  * @since 7.0.0
851
  *
852
- * @param array $tags Allowed tags, attributes, and/or entities.
853
  * @param string $context Context to judge allowed tags by. Allowed values are 'post'.
854
  *
855
  * @return array
856
  */
857
  function qsm_custom_wpkses_post_tags( $tags, $context ) {
858
-
859
  if ( 'post' === $context ) {
860
  $tags['iframe'] = array(
861
  'src' => true,
@@ -884,15 +884,36 @@ add_filter( 'wp_kses_allowed_html', 'qsm_custom_wpkses_post_tags', 10, 2 );
884
  *
885
  * @since 7.1.3
886
  *
887
- * @param arr $mlw_quiz_array
888
- * @param str $qmn_question_answer_template
889
- * @param str $answer
890
- * @param int $qsm_question_cnt
891
- * @param int $total_question_cnt
892
  * @return string
893
  */
894
  function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question_answer_template, $questions, $qmn_questions, $answer, $qsm_question_cnt, $total_question_cnt ) {
895
  global $mlwQuizMasterNext;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
896
  if ( is_admin() && isset( $_GET['page'] ) && sanitize_text_field( wp_unslash( $_GET['page'] ) ) == 'qsm_quiz_result_details' ) {
897
  $user_answer_class = '';
898
  $question_answer_class = '';
@@ -908,7 +929,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
908
  }
909
  }
910
  } else {
911
- if ( isset( $mlw_quiz_array['form_type'] ) && "1" === $mlw_quiz_array['form_type'] ) {
912
  $user_answer_class = 'qmn_user_correct_answer';
913
  $question_answer_class = 'qmn_question_answer_correct';
914
  } else {
@@ -921,7 +942,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
921
  }
922
  }
923
  }
924
- $open_span_tag = '<span class="'.$user_answer_class.'">';
925
  $mlw_question_answer_display = htmlspecialchars_decode( $qmn_question_answer_template, ENT_QUOTES );
926
  $disable_description_on_result = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'disable_description_on_result' );
927
  // Get question setting
@@ -934,7 +955,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
934
  if ( 1 == $disable_description_on_result ) {
935
  $mlw_question_answer_display = str_replace( '%QUESTION%', '<b>' . htmlspecialchars_decode( $answer['question_title'], ENT_QUOTES ) . '</b>', $mlw_question_answer_display );
936
  } else {
937
- $mlw_question_answer_display = str_replace( '%QUESTION%', '<b>' . htmlspecialchars_decode( $answer['question_title'], ENT_QUOTES ) . '</b>' . $add_br . htmlspecialchars_decode( $answer[0], ENT_QUOTES ).$add_br, $mlw_question_answer_display );
938
  }
939
  } else {
940
  $mlw_question_answer_display = str_replace( '%QUESTION%', '<b>' . htmlspecialchars_decode( $answer[0], ENT_QUOTES ) . '</b>', $mlw_question_answer_display );
@@ -951,23 +972,24 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
951
  12,
952
  5,
953
  7,
954
- // 14,
955
  );
956
  $form_type = isset( $mlw_quiz_array['form_type'] ) ? $mlw_quiz_array['form_type'] : 0;
957
  $quiz_system = isset( $mlw_quiz_array['quiz_system'] ) ? $mlw_quiz_array['quiz_system'] : 0;
958
  if ( isset( $answer['id'] ) && isset( $questions[ $answer['id'] ] ) && ! empty( $questions[ $answer['id'] ] ) ) {
959
- $total_answers = isset( $questions[ $answer['id'] ]['answers'] ) ? $questions[ $answer['id'] ]['answers'] : array();
960
- $qsm_random_quetion_answer = get_post_meta($answer['id'],'qsm_random_quetion_answer',true);
961
- if ( ! empty($qsm_random_quetion_answer) ) {
962
  $total_answers = $qsm_random_quetion_answer;
963
  // No longer Need This Value
964
- delete_post_meta( $answer['id'], 'qsm_random_quetion_answer');
965
  }
966
  if ( $total_answers ) {
967
  if ( isset( $answer['question_type'] ) && in_array( intval( $answer['question_type'] ), $show_two_option_questions, true ) ) {
968
  $do_show_wrong = true;
969
  foreach ( $total_answers as $single_answer ) {
970
  $current_answer_zero = trim( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) );
 
971
  if ( 0 == $form_type && ( 0 == $quiz_system || 3 == $quiz_system ) ) {
972
  if ( isset( $single_answer[2] ) && 1 == $single_answer[2] ) {
973
  $actual_answer = htmlspecialchars_decode( $answer[1], ENT_QUOTES );
@@ -1013,22 +1035,28 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1013
  } elseif ( isset( $answer['question_type'] ) && 14 == $answer['question_type'] ) {
1014
  $match_answer = $mlwQuizMasterNext->pluginHelper->get_question_setting( $answer['id'], 'matchAnswer' );
1015
  $new_array_user_answer = isset( $answer['user_compare_text'] ) ? explode( '=====', $answer['user_compare_text'] ) : array();
 
1016
  if ( 'sequence' === $match_answer ) {
1017
  foreach ( $total_answers as $key => $single_answer ) {
1018
- $show_user_answer = $new_array_user_answer[ $key ];
1019
- $is_answer_correct = false;
1020
- if ( mb_strtoupper( $show_user_answer ) == mb_strtoupper( $single_answer[0] ) ) {
 
 
 
1021
  $is_answer_correct = true;
1022
  }
1023
  $index = $key + 1;
 
1024
  if ( $is_answer_correct ) {
1025
  $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer">(' . $index . ') ' . $show_user_answer . '</span>';
1026
  } else {
1027
  if ( '' === $show_user_answer ) {
1028
  $show_user_answer = 'No answer provided';
1029
  }
 
1030
  $question_with_answer_text .= '<span class="qsm-text-wrong-option">(' . $index . ') ' . $show_user_answer . '</span>';
1031
- $question_with_answer_text .= '<span class="qsm-text-correct-option">(' . $index . ') ' . $single_answer[0] . '</span>';
1032
  }
1033
  }
1034
  } else {
@@ -1083,7 +1111,9 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1083
  }
1084
  }
1085
  }
 
1086
  $image_class = '';
 
1087
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
1088
  $show_user_answer = '<img src="' . htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) . '"/>';
1089
  $image_class = 'qmn_image_option';
@@ -1105,7 +1135,9 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1105
  if ( 13 == $answer['question_type'] ) {
1106
  $questionid = $questions[ $answer['id'] ]['question_id'];
1107
  $question_with_answer_text .= qmn_polar_display_on_resultspage( $questionid, $questions, $total_answers, $answer );
1108
-
 
 
1109
  } else {
1110
  foreach ( $total_answers as $single_answer ) {
1111
  $single_answer_option = $single_answer[0];
@@ -1124,7 +1156,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1124
  $answer_value = htmlspecialchars( $answer_value );
1125
  }
1126
  } else {
1127
- $answer_value = htmlspecialchars_decode( $answer[1], ENT_QUOTES );
1128
  }
1129
  $image_class = '';
1130
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] ) {
@@ -1169,6 +1201,9 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1169
  $questionid = $questions[ $answer['id'] ]['question_id'];
1170
 
1171
  $question_with_answer_text .= qmn_polar_display_on_resultspage( $questionid, $questions, $total_answers, $answer );
 
 
 
1172
  } else {
1173
  foreach ( $total_answers as $single_answer ) {
1174
  $image_class = '';
@@ -1210,9 +1245,13 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1210
  $file_extension = substr( $answer[1], -4 );
1211
  if ( '.jpg' === $file_extension || '.jpeg' === $file_extension || '.png' === $file_extension || '.gif' === $file_extension ) {
1212
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag<img src='$answer[1]'/>$close_span_with_br", $mlw_question_answer_display );
1213
- }else {
1214
  $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 );
1215
  }
 
 
 
 
1216
  } else {
1217
  $user_answer_new = $answer[1];
1218
  if ( ( 0 == $answer['question_type'] || 1 == $answer['question_type'] || 2 == $answer['question_type'] ) && '' === $answer[1] ) {
@@ -1221,18 +1260,22 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
1221
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] && '' !== $user_answer_new ) {
1222
  $image_url = htmlspecialchars_decode( $user_answer_new, ENT_QUOTES );
1223
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag<img src='$image_url'/>$close_span_with_br", $mlw_question_answer_display );
1224
- }elseif ( 5 == $answer['question_type'] ) {
1225
- $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag" . nl2br(htmlspecialchars_decode( $user_answer_new, ENT_QUOTES )) . $close_span_with_br, $mlw_question_answer_display );
1226
- } else {
1227
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag" . htmlspecialchars_decode( $user_answer_new, ENT_QUOTES ) . $close_span_with_br, $mlw_question_answer_display );
1228
  }
1229
  }
1230
  $answer_2 = ! empty( $answer[2] ) ? $answer[2] : 'NA';
1231
- if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] && 'NA' !== $answer_2 ) {
 
 
 
 
1232
  $image_url = htmlspecialchars_decode( $answer_2, ENT_QUOTES );
1233
  $mlw_question_answer_display = str_replace( '%CORRECT_ANSWER%', '<br/><img src="' . $image_url . '"/>', $mlw_question_answer_display );
1234
  } else {
1235
- $mlw_question_answer_display = str_replace( '%CORRECT_ANSWER%', ''.htmlspecialchars_decode( $answer_2, ENT_QUOTES ).'<br/>', $mlw_question_answer_display );
1236
  }
1237
  $answer_3 = ! empty( $answer[3] ) ? $answer[3] : 'NA';
1238
  $mlw_question_answer_display = str_replace( '%USER_COMMENTS%', $answer_3, $mlw_question_answer_display );
@@ -1266,7 +1309,15 @@ function qsm_get_question_maximum_points( $question = array() ) {
1266
  }
1267
  }
1268
  $question_max_point = max( $answer_points );
1269
- if ( 4 == $question['question_type_new'] || 10 == $question['question_type_new'] ) {
 
 
 
 
 
 
 
 
1270
  $limit_multiple_response = ( isset( $question['settings']['limit_multiple_response'] ) ) ? intval( $question['settings']['limit_multiple_response'] ) : 0;
1271
  if ( $limit_multiple_response > 0 && count( $answer_points ) > $limit_multiple_response ) {
1272
  rsort( $answer_points );
@@ -1295,7 +1346,6 @@ function qsm_is_allow_score_roundoff() {
1295
  } else {
1296
  return 0;
1297
  }
1298
-
1299
  }
1300
  /**
1301
  * Display Polor Question on Result page
@@ -1305,7 +1355,7 @@ function qsm_is_allow_score_roundoff() {
1305
  * @params @answers The array that contains the answers to the question.
1306
  * @params @answer The array that contains the answers choose by user.
1307
  * @return $question_display Returns the content of the question
1308
- * @since 7.1.10
1309
  */
1310
  function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) {
1311
  $question_display = '';
@@ -1318,22 +1368,22 @@ function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) {
1318
  $input_text = '';
1319
  $first_point = isset( $answers[0][1] ) ? intval( $answers[0][1] ) : 0;
1320
  $second_point = isset( $answers[1][1] ) ? intval( $answers[1][1] ) : 0;
1321
- $mid_point = ( $second_point - $first_point ) / 2;
1322
  $is_reverse = false;
1323
  if ( $first_point > $second_point ) {
1324
- $is_reverse = true;
1325
- $mid_point = ( $first_point - $second_point ) / 2;
1326
  }
1327
- $total_answer = count( $answers );
1328
- $id = esc_attr( intval( $id ) );
1329
- $answar1 = $first_point;
1330
- $answar2 = $second_point;
1331
- $user_answer = $answer[1] ;
1332
- $slider_date_atts = '';
1333
- $slider_date_atts .= ' data-answer1="'.$answar1.'" ';
1334
- $slider_date_atts .= ' data-answer2="'.$answar2.'" ';
1335
- $slider_date_atts .= ' data-is_reverse="'.intval($is_reverse).'" ';
1336
- $slider_date_atts .= ' data-answer_value="'.$user_answer.'" ';
1337
  $mlw_require_class = '';
1338
  if ( 0 == $required ) {
1339
  $mlw_require_class = 'mlwRequiredText';
@@ -1344,21 +1394,21 @@ function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) {
1344
  } elseif ( $answer['points'] == $answar2 ) {
1345
  $left_polar_title_style = "style='font-weight:100;'";
1346
  $right_polar_title_style = "style='font-weight:900;'";
1347
- } elseif ( $answer['points'] == $mid_point ) {
1348
  $left_polar_title_style = "style='font-weight:600;'";
1349
  $right_polar_title_style = "style='font-weight:600;'";
1350
  } elseif ( $answer['points'] < $mid_point ) {
1351
- $left_polar_title_style = "style='font-weight:400;'";
1352
- $right_polar_title_style = "style='font-weight:600;'";
1353
- } elseif ( $answer['points'] > $mid_point ) {
1354
  $left_polar_title_style = "style='font-weight:600;'";
1355
  $right_polar_title_style = "style='font-weight:400;'";
 
 
 
1356
  }
1357
  if ( $is_reverse ) {
1358
  if ( $answer['points'] < $mid_point ) {
1359
  $left_polar_title_style = "style='font-weight:400;'";
1360
  $right_polar_title_style = "style='font-weight:600;'";
1361
- } elseif ( $answer['points'] > $mid_point ) {
1362
  $left_polar_title_style = "style='font-weight:600;'";
1363
  $right_polar_title_style = "style='font-weight:400;'";
1364
  }
@@ -1367,7 +1417,7 @@ function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) {
1367
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
1368
  $input_text .= "<div class='left-polar-title' $left_polar_title_style >" . $answers[0][0] . '</div>';
1369
  $input_text .= "<div class='slider-main-wrapper'><input type='hidden' class='qmn_polar $mlw_require_class' id='question" . esc_attr( $id ) . "' name='question" . esc_attr( $id ) . "' />";
1370
- $input_text .= '<div id="slider-' . esc_attr( $id ) . '"'.$slider_date_atts.'></div></div>';
1371
  $input_text .= "<div class='right-polar-title' $right_polar_title_style>" . $answers[1][0] . '</div>';
1372
  $question = $input_text;
1373
  $question_display .= "<span class='mlw_qmn_question mlw-qmn-question-result-$id question-type-polar-s'>" . do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) . '</span>';
@@ -1380,7 +1430,7 @@ function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) {
1380
  * @params $data Questions Data
1381
  * @params $strip Can Stripable ot not?
1382
  * @return $question_display Returns the content of the question
1383
- * @since 7.3.3
1384
  */
1385
  function qmn_sanitize_input_data( $data, $strip = false ) {
1386
  if ( $strip ) {
@@ -1394,8 +1444,8 @@ function qmn_sanitize_input_data( $data, $strip = false ) {
1394
  *
1395
  * @since 7.0.2
1396
  *
1397
- * @param string $content
1398
- * @param array $mlw_quiz_array
1399
  * @return string $content
1400
  */
1401
  function qsm_variable_minimum_points( $content, $mlw_quiz_array ) {
@@ -1410,10 +1460,10 @@ function qsm_variable_minimum_points( $content, $mlw_quiz_array ) {
1410
  *
1411
  * @since 7.3.6
1412
  *
1413
- * @param string $question
1414
- * @param string $question_type
1415
- * @param string $new_question_title
1416
- * @param int $question_id
1417
  * @return string $question_display
1418
  */
1419
  function qsm_varibale_question_title_func( $question, $question_type = '', $new_question_title = '', $question_id = 0 ) {
@@ -1445,4 +1495,4 @@ function qsm_varibale_question_title_func( $question, $question_type = '', $new_
1445
 
1446
  $question_display .= "<div class='mlw_qmn_question {$polar_extra_class}' >" . do_shortcode( htmlspecialchars_decode( $question_title, ENT_QUOTES ) ) . $deselect_answer . '</div>';
1447
  return $question_display;
1448
- }
1
  <?php
 
 
 
 
2
  /**
3
  * This file contains all the variables that are in the plugin. It registers them and then makes them available for use.
4
  *
6
  *
7
  * @since 4.4.0
8
  */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
  /*
15
  Results Array For Reference:
16
 
66
  add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_total_possible_points', 10, 2 );
67
  add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_total_attempted_questions', 10, 2 );
68
  add_filter( 'mlw_qmn_template_variable_results_page', 'mlw_qmn_variable_user_full_name', 10, 2 );
69
+ add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_poll_result', 10, 3 );
70
  add_filter( 'qmn_end_results', 'qsm_variable_poll_result', 10, 3 );
71
  add_filter( 'mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_quiz_name', 10, 2 );
72
  add_filter( 'mlw_qmn_template_variable_quiz_page', 'mlw_qmn_variable_quiz_links', 10, 2 );
76
  add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_variable_minimum_points', 10, 2 );
77
 
78
  /**
79
+ * Changed the display structure to new structure.
80
+ *
81
  * @since 6.4.11
 
82
  * @param str $content
83
  * @param array $mlw_quiz_array
84
  * Show particular question answer.
133
  *
134
  * @since 7.0.2
135
  *
136
+ * @param string $content
137
+ * @param array $mlw_quiz_array
138
  * @return string $content
139
  */
140
  function qsm_variable_total_possible_points( $content, $mlw_quiz_array ) {
149
  *
150
  * @since 7.0.2
151
  *
152
+ * @param string $content
153
+ * @param array $mlw_quiz_array
154
  * @return string $content
155
  */
156
  function qsm_variable_total_attempted_questions( $content, $mlw_quiz_array ) {
165
  * @param str $content
166
  * @param arr $mlw_quiz_array
167
  */
168
+ function qsm_variable_poll_result( $content, $mlw_quiz_array ) {
169
  $quiz_id = is_object( $mlw_quiz_array ) ? $mlw_quiz_array->quiz_id : $mlw_quiz_array['quiz_id'];
170
  while ( false !== strpos( $content, '%POLL_RESULTS_' ) ) {
171
  $question_id = mlw_qmn_get_string_between( $content, '%POLL_RESULTS_', '%' );
178
  $total_result = $total_query['total_count'];
179
  $ser_answer = $wpdb->get_row( $wpdb->prepare( "SELECT answer_array,question_settings FROM {$wpdb->prefix}mlw_questions WHERE question_id = %d", $question_id ), ARRAY_A );
180
  $ser_answer_arry = qmn_sanitize_input_data( $ser_answer['answer_array'] );
181
+ $question_settings = qmn_sanitize_input_data( $ser_answer['question_settings'] );
182
  $ser_answer_arry_change = array_filter( array_merge( array( 0 ), $ser_answer_arry ) );
183
  $total_quiz_results = $wpdb->get_results( $wpdb->prepare( "SELECT quiz_results FROM {$wpdb->prefix}mlw_results WHERE quiz_id = %d", $quiz_id ), ARRAY_A );
184
  $answer_array = array();
199
  if ( '' !== $answer_str && qsm_find_key_from_array( $answer_str, $ser_answer_arry_change ) ) {
200
  $percentage = number_format( $answer_count / $total_result * 100, 2 );
201
  $answer_str = qsm_answers_type_evaluated( $answer_str, $question_settings );
202
+ $str .= $answer_str . ' : ' . $percentage . '%<br/>';
203
+ $str .= '<progress value="' . $percentage . '" max="100">' . $percentage . ' %</progress><br/>';
204
  }
205
  }
206
  }
324
  /**
325
  * Return total incorrect amount
326
  *
327
+ * @since 7.0.3
328
+ * @param string $content
329
+ * @param array $mlw_quiz_array
330
  * @return string
331
  */
332
  function mlw_qmn_variable_amount_incorrect( $content, $mlw_quiz_array ) {
384
  /**
385
  * Returns full name of user
386
  *
387
+ * @since 7.1.11
388
+ * @param string $content
389
+ * @param array $mlw_quiz_array
390
  * @return string
391
  */
392
  function mlw_qmn_variable_user_full_name( $content, $mlw_quiz_array ) {
423
  /**
424
  * Returns user value for supplied contact field
425
  *
426
+ * @since 5.0.0
427
  * @return string The HTML for the content
428
  */
429
  function qsm_contact_field_variable( $content, $results_array ) {
437
  /**
438
  * Returns user values for all contact fields
439
  *
440
+ * @since 5.0.0
441
  * @return string The HTML for the content
442
  */
443
  function qsm_all_contact_fields_variable( $content, $results ) {
454
  /**
455
  * Converts the %QUESTIONS_ANSWERS% into the template
456
  *
457
+ * @param string $content The content to be checked for the template
458
  * @param array $mlw_quiz_array The array for the response data
459
  */
460
  function mlw_qmn_variable_question_answers( $content, $mlw_quiz_array ) {
532
  /**
533
  * Replaces the variable %CURRENT_DATE% and displays the current date
534
  *
535
+ * @param string $content The contents of the results page
536
+ * @param array $results The array of all the results from user taking the quiz
537
  * @return string Returns the contents for the results page
538
  */
539
  function mlw_qmn_variable_date( $content, $results ) {
545
  /**
546
  * Replaces the variable %DATE_TAKEN% and returns the date the user submitted his or her responses
547
  *
548
+ * @param string $content The contents of the results page
549
+ * @param array $results The array of all the results from user taking the quiz
550
  * @return string Returns the contents for the results page
551
  */
552
  function mlw_qmn_variable_date_taken( $content, $mlw_quiz_array ) {
590
  $length++;
591
  }
592
  }
593
+ if ( sizeof( $category_data['ids'] ) == $length ) {
594
  $return_points += $answer['points'];
595
  }
596
  } else {
632
  foreach ( $mlw_quiz_array['question_answers_array'] as $answer ) {
633
  if ( is_array( $answer['multicategories'] ) ) {
634
  foreach ( $answer['multicategories'] as $category ) {
635
+ $category_name_object = get_term_by( 'ID', $category, 'qsm_category' );
636
  $category_name_of_question = ( ! empty( $category_name_object->name ) ? $category_name_object->name : '' );
637
+ if ( $category_name_object->name == $category_name && '11' !== $answer['question_type'] ) {
638
  $total_questions += 1;
639
+ $return_points += $answer['points'];
640
  }
641
  }
642
  }
695
  $length++;
696
  }
697
  }
698
+ if ( sizeof( $category_data['ids'] ) == $length ) {
699
  $total_questions += 1;
700
  if ( 'correct' === $answer['correct'] ) {
701
  $amount_correct += 1;
846
  }
847
 
848
  /**
 
849
  * Add iFrame to allowed wp_kses_post tags
850
  *
851
  * @since 7.0.0
852
  *
853
+ * @param array $tags Allowed tags, attributes, and/or entities.
854
  * @param string $context Context to judge allowed tags by. Allowed values are 'post'.
855
  *
856
  * @return array
857
  */
858
  function qsm_custom_wpkses_post_tags( $tags, $context ) {
 
859
  if ( 'post' === $context ) {
860
  $tags['iframe'] = array(
861
  'src' => true,
884
  *
885
  * @since 7.1.3
886
  *
887
+ * @param arr $mlw_quiz_array
888
+ * @param str $qmn_question_answer_template
889
+ * @param str $answer
890
+ * @param int $qsm_question_cnt
891
+ * @param int $total_question_cnt
892
  * @return string
893
  */
894
  function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question_answer_template, $questions, $qmn_questions, $answer, $qsm_question_cnt, $total_question_cnt ) {
895
  global $mlwQuizMasterNext;
896
+ $question_types = $mlwQuizMasterNext->pluginHelper->get_question_type_options();
897
+
898
+ $use_custom_default_template = array();
899
+ foreach ( $question_types as $type ) {
900
+ if ( isset( $type['options']['use_custom_default_template'] ) && $type['options']['use_custom_default_template'] ) {
901
+ $use_custom_default_template[] = $type['slug'];
902
+ }
903
+ }
904
+ $use_custom_user_answer_template = array();
905
+ foreach ( $question_types as $type ) {
906
+ if ( isset( $type['options']['use_custom_user_answer_template'] ) && $type['options']['use_custom_user_answer_template'] ) {
907
+ $use_custom_user_answer_template[] = $type['slug'];
908
+ }
909
+ }
910
+ $use_custom_correct_answer_template = array();
911
+ foreach ( $question_types as $type ) {
912
+ if ( isset( $type['options']['use_custom_correct_answer_template'] ) && $type['options']['use_custom_correct_answer_template'] ) {
913
+ $use_custom_correct_answer_template[] = $type['slug'];
914
+ }
915
+ }
916
+
917
  if ( is_admin() && isset( $_GET['page'] ) && sanitize_text_field( wp_unslash( $_GET['page'] ) ) == 'qsm_quiz_result_details' ) {
918
  $user_answer_class = '';
919
  $question_answer_class = '';
929
  }
930
  }
931
  } else {
932
+ if ( isset( $mlw_quiz_array['form_type'] ) && '1' === $mlw_quiz_array['form_type'] ) {
933
  $user_answer_class = 'qmn_user_correct_answer';
934
  $question_answer_class = 'qmn_question_answer_correct';
935
  } else {
942
  }
943
  }
944
  }
945
+ $open_span_tag = '<span class="' . $user_answer_class . '">';
946
  $mlw_question_answer_display = htmlspecialchars_decode( $qmn_question_answer_template, ENT_QUOTES );
947
  $disable_description_on_result = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'disable_description_on_result' );
948
  // Get question setting
955
  if ( 1 == $disable_description_on_result ) {
956
  $mlw_question_answer_display = str_replace( '%QUESTION%', '<b>' . htmlspecialchars_decode( $answer['question_title'], ENT_QUOTES ) . '</b>', $mlw_question_answer_display );
957
  } else {
958
+ $mlw_question_answer_display = str_replace( '%QUESTION%', '<b>' . htmlspecialchars_decode( $answer['question_title'], ENT_QUOTES ) . '</b>' . $add_br . htmlspecialchars_decode( $answer[0], ENT_QUOTES ) . $add_br, $mlw_question_answer_display );
959
  }
960
  } else {
961
  $mlw_question_answer_display = str_replace( '%QUESTION%', '<b>' . htmlspecialchars_decode( $answer[0], ENT_QUOTES ) . '</b>', $mlw_question_answer_display );
972
  12,
973
  5,
974
  7,
975
+ // 14,
976
  );
977
  $form_type = isset( $mlw_quiz_array['form_type'] ) ? $mlw_quiz_array['form_type'] : 0;
978
  $quiz_system = isset( $mlw_quiz_array['quiz_system'] ) ? $mlw_quiz_array['quiz_system'] : 0;
979
  if ( isset( $answer['id'] ) && isset( $questions[ $answer['id'] ] ) && ! empty( $questions[ $answer['id'] ] ) ) {
980
+ $total_answers = isset( $questions[ $answer['id'] ]['answers'] ) ? $questions[ $answer['id'] ]['answers'] : array();
981
+ $qsm_random_quetion_answer = get_post_meta( $answer['id'], 'qsm_random_quetion_answer', true );
982
+ if ( ! empty( $qsm_random_quetion_answer ) ) {
983
  $total_answers = $qsm_random_quetion_answer;
984
  // No longer Need This Value
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 ) ) {
994
  if ( isset( $single_answer[2] ) && 1 == $single_answer[2] ) {
995
  $actual_answer = htmlspecialchars_decode( $answer[1], ENT_QUOTES );
1035
  } elseif ( isset( $answer['question_type'] ) && 14 == $answer['question_type'] ) {
1036
  $match_answer = $mlwQuizMasterNext->pluginHelper->get_question_setting( $answer['id'], 'matchAnswer' );
1037
  $new_array_user_answer = isset( $answer['user_compare_text'] ) ? explode( '=====', $answer['user_compare_text'] ) : array();
1038
+
1039
  if ( 'sequence' === $match_answer ) {
1040
  foreach ( $total_answers as $key => $single_answer ) {
1041
+ $show_user_answer = $new_array_user_answer[ $key ];
1042
+
1043
+ $is_answer_correct = false;
1044
+ $decode_show_user_answer = htmlspecialchars_decode( mb_strtoupper( $show_user_answer ), ENT_QUOTES );
1045
+ $decode_single_user_answer = mb_strtoupper( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) );
1046
+ if ( $decode_show_user_answer == $decode_single_user_answer ) {
1047
  $is_answer_correct = true;
1048
  }
1049
  $index = $key + 1;
1050
+
1051
  if ( $is_answer_correct ) {
1052
  $question_with_answer_text .= '<span class="qsm-text-correct-option qsm-text-user-correct-answer">(' . $index . ') ' . $show_user_answer . '</span>';
1053
  } else {
1054
  if ( '' === $show_user_answer ) {
1055
  $show_user_answer = 'No answer provided';
1056
  }
1057
+
1058
  $question_with_answer_text .= '<span class="qsm-text-wrong-option">(' . $index . ') ' . $show_user_answer . '</span>';
1059
+ $question_with_answer_text .= '<span class="qsm-text-correct-option">(' . $index . ') ' . strval( htmlspecialchars_decode( $single_answer[0], ENT_QUOTES ) ) . '</span>';
1060
  }
1061
  }
1062
  } else {
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';
1135
  if ( 13 == $answer['question_type'] ) {
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];
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'] ) {
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 = '';
1245
  $file_extension = substr( $answer[1], -4 );
1246
  if ( '.jpg' === $file_extension || '.jpeg' === $file_extension || '.png' === $file_extension || '.gif' === $file_extension ) {
1247
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag<img src='$answer[1]'/>$close_span_with_br", $mlw_question_answer_display );
1248
+ } else {
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];
1257
  if ( ( 0 == $answer['question_type'] || 1 == $answer['question_type'] || 2 == $answer['question_type'] ) && '' === $answer[1] ) {
1260
  if ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] && '' !== $user_answer_new ) {
1261
  $image_url = htmlspecialchars_decode( $user_answer_new, ENT_QUOTES );
1262
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag<img src='$image_url'/>$close_span_with_br", $mlw_question_answer_display );
1263
+ } elseif ( 5 == $answer['question_type'] ) {
1264
+ $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag" . nl2br( htmlspecialchars_decode( $user_answer_new, ENT_QUOTES ) ) . $close_span_with_br, $mlw_question_answer_display );
1265
+ } else {
1266
  $mlw_question_answer_display = str_replace( '%USER_ANSWER%', "$open_span_tag" . htmlspecialchars_decode( $user_answer_new, ENT_QUOTES ) . $close_span_with_br, $mlw_question_answer_display );
1267
  }
1268
  }
1269
  $answer_2 = ! empty( $answer[2] ) ? $answer[2] : 'NA';
1270
+ if ( in_array( $answer['question_type'], $use_custom_correct_answer_template, true ) ) {
1271
+ $questionid = $answer['question_type'];
1272
+ $qsm_correct_ans = apply_filters( 'qsm_result_page_custom_correct_answer_template', $questionid, $answer );
1273
+ $mlw_question_answer_display = str_replace( '%CORRECT_ANSWER%', $qsm_correct_ans, $mlw_question_answer_display );
1274
+ } elseif ( isset( $question_settings['answerEditor'] ) && 'image' === $question_settings['answerEditor'] && 'NA' !== $answer_2 ) {
1275
  $image_url = htmlspecialchars_decode( $answer_2, ENT_QUOTES );
1276
  $mlw_question_answer_display = str_replace( '%CORRECT_ANSWER%', '<br/><img src="' . $image_url . '"/>', $mlw_question_answer_display );
1277
  } else {
1278
+ $mlw_question_answer_display = str_replace( '%CORRECT_ANSWER%', '' . htmlspecialchars_decode( $answer_2, ENT_QUOTES ) . '<br/>', $mlw_question_answer_display );
1279
  }
1280
  $answer_3 = ! empty( $answer[3] ) ? $answer[3] : 'NA';
1281
  $mlw_question_answer_display = str_replace( '%USER_COMMENTS%', $answer_3, $mlw_question_answer_display );
1309
  }
1310
  }
1311
  $question_max_point = max( $answer_points );
1312
+ global $mlwQuizMasterNext;
1313
+ $question_types = $mlwQuizMasterNext->pluginHelper->get_question_type_options();
1314
+ $multiple_choise = array();
1315
+ foreach ( $question_types as $type ) {
1316
+ if ( isset( $type['options']['multiple_choise'] ) && $type['options']['multiple_choise'] ) {
1317
+ $multiple_choise[] = $type['slug'];
1318
+ }
1319
+ }
1320
+ if ( 4 == $question['question_type_new'] || 10 == $question['question_type_new'] || in_array( $question['question_type_new'], $multiple_choise, true ) ) {
1321
  $limit_multiple_response = ( isset( $question['settings']['limit_multiple_response'] ) ) ? intval( $question['settings']['limit_multiple_response'] ) : 0;
1322
  if ( $limit_multiple_response > 0 && count( $answer_points ) > $limit_multiple_response ) {
1323
  rsort( $answer_points );
1346
  } else {
1347
  return 0;
1348
  }
 
1349
  }
1350
  /**
1351
  * Display Polor Question on Result page
1355
  * @params @answers The array that contains the answers to the question.
1356
  * @params @answer The array that contains the answers choose by user.
1357
  * @return $question_display Returns the content of the question
1358
+ * @since 7.1.10
1359
  */
1360
  function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) {
1361
  $question_display = '';
1368
  $input_text = '';
1369
  $first_point = isset( $answers[0][1] ) ? intval( $answers[0][1] ) : 0;
1370
  $second_point = isset( $answers[1][1] ) ? intval( $answers[1][1] ) : 0;
1371
+ $mid_point = ( $second_point - $first_point ) / 2;
1372
  $is_reverse = false;
1373
  if ( $first_point > $second_point ) {
1374
+ $is_reverse = true;
1375
+ $mid_point = ( $first_point - $second_point ) / 2;
1376
  }
1377
+ $total_answer = count( $answers );
1378
+ $id = esc_attr( intval( $id ) );
1379
+ $answar1 = $first_point;
1380
+ $answar2 = $second_point;
1381
+ $user_answer = $answer[1];
1382
+ $slider_date_atts = '';
1383
+ $slider_date_atts .= ' data-answer1="' . $answar1 . '" ';
1384
+ $slider_date_atts .= ' data-answer2="' . $answar2 . '" ';
1385
+ $slider_date_atts .= ' data-is_reverse="' . intval( $is_reverse ) . '" ';
1386
+ $slider_date_atts .= ' data-answer_value="' . $user_answer . '" ';
1387
  $mlw_require_class = '';
1388
  if ( 0 == $required ) {
1389
  $mlw_require_class = 'mlwRequiredText';
1394
  } elseif ( $answer['points'] == $answar2 ) {
1395
  $left_polar_title_style = "style='font-weight:100;'";
1396
  $right_polar_title_style = "style='font-weight:900;'";
1397
+ } elseif ( $answer['points'] == $mid_point ) {
1398
  $left_polar_title_style = "style='font-weight:600;'";
1399
  $right_polar_title_style = "style='font-weight:600;'";
1400
  } elseif ( $answer['points'] < $mid_point ) {
 
 
 
1401
  $left_polar_title_style = "style='font-weight:600;'";
1402
  $right_polar_title_style = "style='font-weight:400;'";
1403
+ } elseif ( $answer['points'] > $mid_point ) {
1404
+ $left_polar_title_style = "style='font-weight:400;'";
1405
+ $right_polar_title_style = "style='font-weight:600;'";
1406
  }
1407
  if ( $is_reverse ) {
1408
  if ( $answer['points'] < $mid_point ) {
1409
  $left_polar_title_style = "style='font-weight:400;'";
1410
  $right_polar_title_style = "style='font-weight:600;'";
1411
+ } elseif ( $answer['points'] > $mid_point ) {
1412
  $left_polar_title_style = "style='font-weight:600;'";
1413
  $right_polar_title_style = "style='font-weight:400;'";
1414
  }
1417
  $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
1418
  $input_text .= "<div class='left-polar-title' $left_polar_title_style >" . $answers[0][0] . '</div>';
1419
  $input_text .= "<div class='slider-main-wrapper'><input type='hidden' class='qmn_polar $mlw_require_class' id='question" . esc_attr( $id ) . "' name='question" . esc_attr( $id ) . "' />";
1420
+ $input_text .= '<div id="slider-' . esc_attr( $id ) . '"' . $slider_date_atts . '></div></div>';
1421
  $input_text .= "<div class='right-polar-title' $right_polar_title_style>" . $answers[1][0] . '</div>';
1422
  $question = $input_text;
1423
  $question_display .= "<span class='mlw_qmn_question mlw-qmn-question-result-$id question-type-polar-s'>" . do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) . '</span>';
1430
  * @params $data Questions Data
1431
  * @params $strip Can Stripable ot not?
1432
  * @return $question_display Returns the content of the question
1433
+ * @since 7.3.3
1434
  */
1435
  function qmn_sanitize_input_data( $data, $strip = false ) {
1436
  if ( $strip ) {
1444
  *
1445
  * @since 7.0.2
1446
  *
1447
+ * @param string $content
1448
+ * @param array $mlw_quiz_array
1449
  * @return string $content
1450
  */
1451
  function qsm_variable_minimum_points( $content, $mlw_quiz_array ) {
1460
  *
1461
  * @since 7.3.6
1462
  *
1463
+ * @param string $question
1464
+ * @param string $question_type
1465
+ * @param string $new_question_title
1466
+ * @param int $question_id
1467
  * @return string $question_display
1468
  */
1469
  function qsm_varibale_question_title_func( $question, $question_type = '', $new_question_title = '', $question_id = 0 ) {
1495
 
1496
  $question_display .= "<div class='mlw_qmn_question {$polar_extra_class}' >" . do_shortcode( htmlspecialchars_decode( $question_title, ENT_QUOTES ) ) . $deselect_answer . '</div>';
1497
  return $question_display;
1498
+ }
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.6
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -152,6 +152,18 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
152
 
153
  == Changelog ==
154
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  = 7.3.6 (December 10, 2021) =
156
  * Hotfix: Issues with survey form type Fixed
157
  * Hotfix: Issues with simple form fixed
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
 
152
 
153
  == Changelog ==
154
 
155
+ = 7.3.7 (December 27, 2021) =
156
+ * Bug: Fixed issues in fill in the blanks question type
157
+ * Bug: Fixed issues with category selection on result page
158
+ * Bug: Fixed issues with deletion and duplication capabilities for non admin users
159
+ * Bug: Fixed issue where url parameters are being translated
160
+ * Bug: Fixed the issues with category points and score template variables
161
+ * Feature: Added a feature to hide/show columns in admin results page
162
+ * Enhancement: Introduced Page Name and Page URL columns to admin results table
163
+ * Enhancement: Made UI improvements in polar question type slider
164
+ * Enhancement: Made UI improvements in template variable popup
165
+ * Enhancement: Made improvements in Audit Logs
166
+
167
  = 7.3.6 (December 10, 2021) =
168
  * Hotfix: Issues with survey form type Fixed
169
  * Hotfix: Issues with simple form fixed