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

Version Description

(January 31, 2019) = * Closed Enhancement: Create new alert system on quiz options page (Issue #754) * Closed Bug: No access allowed when clicking "Support" from plugins page (Issue #753) * Closed Bug: To many redirects (Issue #745) * Closed User Request: Allow default email to be deleted or turned off (Issue #735) * Closed Enhancement: Rewrite emails to allow for different conditions (Issue #379) * Closed Enhancement: Rewrite results pages to allow for different conditions (Issue #378)

Download this release

Release Info

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

Code changes from version 6.1.2 to 6.2.0

CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 5.3.2 (June 7, 2018) =
2
  * Closed Plugin Compatibility: Conflict with Divi Builder ([Issue #686](https://github.com/fpcorso/quiz_master_next/issues/686))
3
 
1
+ = 6.0.4 (October 2, 2018) =
2
+ * Changes links from old documentation to newer documentation
3
+
4
+ = 6.0.3 (August 20, 2018) =
5
+ * Closed Bug: User gets 'trapped' if timer runs out on required question when questions are paginated ([Issue #583](https://github.com/fpcorso/quiz_master_next/issues/583))
6
+ * Closed Bug: If user refreshes quiz page when timer is at 0, cannot submit ([Issue #501](https://github.com/fpcorso/quiz_master_next/issues/501))
7
+ * Closed Bug: Saving quiz name when editing results in error if no changes are made ([Issue #391](https://github.com/fpcorso/quiz_master_next/issues/391))
8
+ * Adds deprecated notice to the quiz setting functions found in the quizCreator object
9
+ * Adds hook after results are stored in the database
10
+
11
+ = 6.0.2 (July 18, 2018) =
12
+ * Closed Bug: PHP warning thrown on Help page ([Issue #711](https://github.com/fpcorso/quiz_master_next/issues/711))
13
+ * Closed Bug: Timer not working on certain sites when using questions per page option ([Issue #709](https://github.com/fpcorso/quiz_master_next/issues/709))
14
+ * Closed Bug: Blank page shown when contact fields and message fields are empty ([Issue #707](https://github.com/fpcorso/quiz_master_next/issues/707))
15
+
16
+ = 6.0.1 (July 11, 2018) =
17
+ * Closed Bug: Quiz comment box shows HTML in label when using newer pagination system ([Issue #704](https://github.com/fpcorso/quiz_master_next/issues/704))
18
+
19
+ = 6.0.0 (June 20, 2018) =
20
+ * Closed Enhancement: Remove Tools tab ([Issue #689](https://github.com/fpcorso/quiz_master_next/issues/689))
21
+ * Closed Enhancement: Bump Minimum PHP Version To 5.4 ([Issue #607](https://github.com/fpcorso/quiz_master_next/issues/607))
22
+ * Closed Enhancement: Move Leaderboards to free addon ([Issue #380](https://github.com/fpcorso/quiz_master_next/issues/380))
23
+
24
  = 5.3.2 (June 7, 2018) =
25
  * Closed Plugin Compatibility: Conflict with Divi Builder ([Issue #686](https://github.com/fpcorso/quiz_master_next/issues/686))
26
 
css/qsm-admin.css CHANGED
@@ -87,6 +87,142 @@ Options Page
87
  font-weight: bold;
88
  }
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  /********************
91
  Quiz Styles Tab
92
  *********************/
@@ -255,6 +391,18 @@ Help Page
255
  Misc.
256
  *********************/
257
 
 
 
 
 
 
 
 
 
 
 
 
 
258
 
259
  /* Info Bar */
260
  .qsm-info-box {
@@ -290,6 +438,12 @@ Misc.
290
  transform: scale(1.1);
291
  }
292
 
 
 
 
 
 
 
293
  /* Popup */
294
 
295
  .qsm-popup {
87
  font-weight: bold;
88
  }
89
 
90
+ /********************
91
+ Results Pages & Emails Tab
92
+ *********************/
93
+ .results-page,
94
+ .email {
95
+ width: 100%;
96
+ background-color: #0d97d8;
97
+ margin: 20px 0;
98
+ padding-bottom: 15px;
99
+ box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.4)
100
+ }
101
+
102
+ .results-page-header,
103
+ .email-header {
104
+ display: flex;
105
+ align-items: center;
106
+ justify-content: flex-end;
107
+ background-color: #fff;
108
+ padding: 10px 35px;
109
+ border-bottom: 5px solid #1DD969;
110
+ }
111
+
112
+ .delete-page-button,
113
+ .delete-email-button {
114
+ background: none;
115
+ border: none;
116
+ color: #1DD969;
117
+ cursor: pointer;
118
+ transition-duration: 200ms;
119
+ }
120
+
121
+ .delete-page-button:hover,
122
+ .delete-email-button:hover {
123
+ transform: scale(1.2);
124
+ }
125
+
126
+ .results-page-content,
127
+ .email-content {
128
+ display: flex;
129
+ flex-direction: column;
130
+ }
131
+
132
+ .results-page-when,
133
+ .results-page-show,
134
+ .email-when,
135
+ .email-show {
136
+ padding: 10px;
137
+ background-color: #fff;
138
+ border: 5px solid #1DD969;
139
+ margin: 15px 0;
140
+ min-width: 60%;
141
+ }
142
+
143
+ .results-page-content-header,
144
+ .email-content-header {
145
+ margin-bottom: 10px;
146
+ }
147
+
148
+ .results-page-content-header h4,
149
+ .results-page-content-header p,
150
+ .email-content-header h4,
151
+ .email-content-header p {
152
+ margin: 0;
153
+ }
154
+
155
+ .results-page-condition,
156
+ .email-condition {
157
+ display: flex;
158
+ flex-direction: column;
159
+ margin-bottom: 15px;
160
+ justify-content: space-around;
161
+ }
162
+
163
+ .results-page-condition > select,
164
+ .results-page-condition > input,
165
+ .email-condition > select,
166
+ .email-condition > input {
167
+ max-width: 100%;
168
+ }
169
+
170
+ .delete-condition-button {
171
+ background: none;
172
+ border: 1px solid #1DD969;
173
+ color: #1DD969;
174
+ cursor: pointer;
175
+ transition-duration: 200ms;
176
+ padding: 6px;
177
+ }
178
+
179
+ .delete-condition-button:hover {
180
+ transform: scale(1.1);
181
+ }
182
+
183
+ .email-show .label {
184
+ display: block;
185
+ }
186
+
187
+ .results-page-show textarea,
188
+ .to-email,
189
+ .subject,
190
+ .email-template {
191
+ width: 100%;
192
+ margin-bottom: 10px;
193
+ }
194
+
195
+ @media screen and (min-width: 760px) {
196
+ .results-page-content,
197
+ .email-content {
198
+ flex-direction: row;
199
+ justify-content: space-around;
200
+ }
201
+
202
+ .results-page-when,
203
+ .results-page-show,
204
+ .email-when,
205
+ .email-show {
206
+ min-width: 35%;
207
+ }
208
+
209
+ .results-page-condition,
210
+ .email-condition {
211
+ align-items: center;
212
+ flex-direction: row;
213
+ }
214
+ .results-page-condition > select,
215
+ .results-page-condition > input,
216
+ .email-condition > select,
217
+ .email-condition > input {
218
+ max-width: 30%;
219
+ }
220
+
221
+ .delete-condition-button {
222
+ border: none;
223
+ }
224
+ }
225
+
226
  /********************
227
  Quiz Styles Tab
228
  *********************/
391
  Misc.
392
  *********************/
393
 
394
+ /* Ads */
395
+ .help-decide {
396
+ display: block;
397
+ text-align:center;
398
+ background: #fff;
399
+ border: 5px solid #1DD969;
400
+ color: #000;
401
+ font-weight: bold;
402
+ }
403
+ .help-decide p {
404
+ font-size: 14px;
405
+ }
406
 
407
  /* Info Bar */
408
  .qsm-info-box {
438
  transform: scale(1.1);
439
  }
440
 
441
+ /* Options tabs */
442
+ .qsm_tab_content,
443
+ .mlw_tab_content {
444
+ padding: 10px 10px 10px 10px;
445
+ }
446
+
447
  /* Popup */
448
 
449
  .qsm-popup {
js/admin.js CHANGED
@@ -1,24 +1,56 @@
1
-
 
 
2
  var QSMAdmin;
3
  (function ($) {
4
 
5
- QSMAdmin = {
6
- selectTab: function( tab ) {
7
- $( '.qsm-tab' ).removeClass( 'nav-tab-active' );
8
- $( '.qsm-tab-content' ).hide();
9
- tab.addClass( 'nav-tab-active' );
10
- tabID = tab.data( 'tab' );
11
- $( '.tab-' + tabID ).show();
12
- }
13
- };
14
- $(function() {
15
- $( '.qsm-tab' ).on( 'click', function( event ) {
16
- event.preventDefault();
17
- QSMAdmin.selectTab( $( this ) );
18
- });
19
- });
20
- }(jQuery));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- jQuery("#qmn_check_all").change( function() {
23
- jQuery('.qmn_delete_checkbox').prop( 'checked', jQuery('#qmn_check_all').prop('checked') );
24
- });
 
 
1
+ /**
2
+ * Main admin file for functions to be used across many QSM admin pages.
3
+ */
4
  var QSMAdmin;
5
  (function ($) {
6
 
7
+ QSMAdmin = {
8
+ /**
9
+ * Catches an error from a jQuery function (i.e. $.ajax())
10
+ */
11
+ displayjQueryError: function( jqXHR, textStatus, errorThrown ) {
12
+ QSMAdmin.displayAlert( 'Error: ' + errorThrown + '! Please try again.', 'error' );
13
+ },
14
+ /**
15
+ * Catches an error from a BackBone function (i.e. model.save())
16
+ */
17
+ displayError: function( jqXHR, textStatus, errorThrown ) {
18
+ QSMAdmin.displayAlert( 'Error: ' + errorThrown.errorThrown + '! Please try again.', 'error' );
19
+ },
20
+ /**
21
+ * Displays an alert within the "Quiz Settings" page
22
+ *
23
+ * @param string message The message of the alert
24
+ * @param string type The type of alert. Choose from 'error', 'info', 'success', and 'warning'
25
+ */
26
+ displayAlert: function( message, type ) {
27
+ QSMAdmin.clearAlerts();
28
+ var template = wp.template( 'notice' );
29
+ var data = {
30
+ message: message,
31
+ type: type
32
+ };
33
+ $( '.qsm-alerts' ).append( template( data ) );
34
+ },
35
+ clearAlerts: function() {
36
+ $( '.qsm-alerts' ).empty();
37
+ },
38
+ selectTab: function( tab ) {
39
+ $( '.qsm-tab' ).removeClass( 'nav-tab-active' );
40
+ $( '.qsm-tab-content' ).hide();
41
+ tab.addClass( 'nav-tab-active' );
42
+ tabID = tab.data( 'tab' );
43
+ $( '.tab-' + tabID ).show();
44
+ }
45
+ };
46
+ $(function() {
47
+ $( '.qsm-tab' ).on( 'click', function( event ) {
48
+ event.preventDefault();
49
+ QSMAdmin.selectTab( $( this ) );
50
+ });
51
 
52
+ $( '#qmn_check_all' ).change( function() {
53
+ $( '.qmn_delete_checkbox' ).prop( 'checked', jQuery( '#qmn_check_all' ).prop( 'checked' ) );
54
+ });
55
+ });
56
+ }(jQuery));
js/qsm-admin-emails.js ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * QSM - Admin emails
3
+ */
4
+
5
+ var QSMAdminEmails;
6
+ (function ($) {
7
+ QSMAdminEmails = {
8
+ total: 0,
9
+ saveEmails: function() {
10
+ QSMAdmin.displayAlert( 'Saving emails...', 'info' );
11
+ var emails = [];
12
+ var email = {};
13
+ $( '.email' ).each( function() {
14
+ email = {
15
+ 'conditions': [],
16
+ 'to': $( this ).find( '.to-email' ).val(),
17
+ 'subject': $( this ).find( '.subject' ).val(),
18
+ 'content': wp.editor.getContent( $( this ).find( '.email-template' ).attr( 'id' ) ),
19
+ 'replyTo': $( this ).find( '.reply-to' ).prop( 'checked' ),
20
+ };
21
+ $( this ).find( '.email-condition' ).each( function() {
22
+ email.conditions.push({
23
+ 'criteria': $( this ).children( '.email-condition-criteria' ).val(),
24
+ 'operator': $( this ).children( '.email-condition-operator' ).val(),
25
+ 'value': $( this ).children( '.email-condition-value' ).val()
26
+ });
27
+ });
28
+ emails.push( email );
29
+ });
30
+ var data = {
31
+ 'emails': emails
32
+ }
33
+ $.ajax({
34
+ url: wpApiSettings.root + 'quiz-survey-master/v1/quizzes/' + qsmEmailsObject.quizID + '/emails',
35
+ method: 'POST',
36
+ data: data,
37
+ headers: { 'X-WP-Nonce': qsmEmailsObject.nonce },
38
+ })
39
+ .done(function( results ) {
40
+ if ( results.status ) {
41
+ QSMAdmin.displayAlert( 'Emails were saved!', 'success' );
42
+ } else {
43
+ QSMAdmin.displayAlert( 'There was an error when saving the emails. Please try again.', 'error' );
44
+ }
45
+ })
46
+ .fail(QSMAdmin.displayjQueryError);
47
+ },
48
+ loadEmails: function() {
49
+ QSMAdmin.displayAlert( 'Loading emails...', 'info' );
50
+ $.ajax({
51
+ url: wpApiSettings.root + 'quiz-survey-master/v1/quizzes/' + qsmEmailsObject.quizID + '/emails',
52
+ headers: { 'X-WP-Nonce': qsmEmailsObject.nonce },
53
+ })
54
+ .done(function( emails ) {
55
+ emails.forEach( function( email, i, emails ) {
56
+ QSMAdminEmails.addEmail( email.conditions, email.to, email.subject, email.content, email.replyTo );
57
+ });
58
+ QSMAdmin.clearAlerts();
59
+ })
60
+ .fail(QSMAdmin.displayjQueryError);
61
+ },
62
+ addCondition: function( $email, criteria, operator, value ) {
63
+ var template = wp.template( 'email-condition' );
64
+ $email.find( '.email-when-conditions' ).append( template({
65
+ 'criteria': criteria,
66
+ 'operator': operator,
67
+ 'value': value
68
+ }));
69
+ },
70
+ newCondition: function( $email ) {
71
+ QSMAdminEmails.addCondition( $email, 'score', 'equal', 0 );
72
+ },
73
+ addEmail: function( conditions, to, subject, content, replyTo ) {
74
+ QSMAdminEmails.total += 1;
75
+ var template = wp.template( 'email' );
76
+ $( '#emails' ).append( template( { id: QSMAdminEmails.total, to: to, subject: subject, content: content, replyTo: replyTo } ) );
77
+ conditions.forEach( function( condition, i, conditions) {
78
+ QSMAdminEmails.addCondition(
79
+ $( '.email:last-child' ),
80
+ condition.criteria,
81
+ condition.operator,
82
+ condition.value
83
+ );
84
+ });
85
+ var settings = {
86
+ mediaButtons: true,
87
+ tinymce: {
88
+ forced_root_block : '',
89
+ toolbar1: 'formatselect,bold,italic,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,strikethrough,hr,forecolor,pastetext,removeformat,codeformat,charmap,undo,redo'
90
+ },
91
+ quicktags: true,
92
+ };
93
+ wp.editor.initialize( 'email-template-' + QSMAdminEmails.total, settings );
94
+ },
95
+ newEmail: function() {
96
+ var conditions = [{
97
+ 'criteria': 'score',
98
+ 'operator': 'greater',
99
+ 'value': '0'
100
+ }];
101
+ var to = '%USER_EMAIL%';
102
+ var subject = 'Quiz Results For %QUIZ_NAME%';
103
+ var content = '%QUESTIONS_ANSWERS%';
104
+ var replyTo = false;
105
+ QSMAdminEmails.addEmail( conditions, to, subject, content, replyTo );
106
+ }
107
+ };
108
+ $(function() {
109
+ QSMAdminEmails.loadEmails();
110
+
111
+ $( '.add-new-email' ).on( 'click', function( event ) {
112
+ event.preventDefault();
113
+ QSMAdminEmails.newEmail();
114
+ });
115
+ $( '.save-emails' ).on( 'click', function( event ) {
116
+ event.preventDefault();
117
+ QSMAdminEmails.saveEmails();
118
+ });
119
+ $( '#emails' ).on( 'click', '.new-condition', function( event ) {
120
+ event.preventDefault();
121
+ $page = $( this ).closest( '.email' );
122
+ QSMAdminEmails.newCondition( $page );
123
+ });
124
+ $( '#emails' ).on( 'click', '.delete-email-button', function( event ) {
125
+ event.preventDefault();
126
+ $( this ).closest( '.email' ).remove();
127
+ });
128
+ $( '#emails' ).on( 'click', '.delete-condition-button', function( event ) {
129
+ event.preventDefault();
130
+ $( this ).closest( '.email-condition' ).remove();
131
+ });
132
+ });
133
+ }(jQuery));
js/qsm-admin-question.js CHANGED
@@ -76,19 +76,19 @@ var QSMQuestion;
76
  },
77
  addQuestionFromQuestionBank: function( questionID ) {
78
  MicroModal.close( 'modal-2' );
79
- QSMQuestion.displayAlert( 'Adding question...', 'info' );
80
  var model = new QSMQuestion.question( { id: questionID } );
81
  model.fetch({
82
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
83
  url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID,
84
  success: QSMQuestion.questionBankSuccess,
85
- error: QSMQuestion.displayError
86
  });
87
  },
88
  questionBankSuccess: function( model ) {
89
  var page = parseInt( $( '#add-question-bank-page' ).val(), 10 );
90
  model.set( 'page', page );
91
- QSMQuestion.displayAlert( 'Question added!', 'success' );
92
  QSMQuestion.questions.add( model );
93
  QSMQuestion.addQuestionToPage( model );
94
  },
@@ -112,16 +112,16 @@ var QSMQuestion;
112
  $( '#categories' ).prepend( template( { category: category } ) );
113
  },
114
  loadQuestions: function() {
115
- QSMQuestion.displayAlert( 'Loading questions...', 'info' );
116
  QSMQuestion.questions.fetch({
117
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
118
  data: { quizID: qsmQuestionSettings.quizID },
119
  success: QSMQuestion.loadSuccess,
120
- error: QSMQuestion.displayError
121
  });
122
  },
123
  loadSuccess: function() {
124
- QSMQuestion.clearAlerts();
125
  var question;
126
  if ( qsmQuestionSettings.pages.length > 0 ) {
127
  for ( var i = 0; i < qsmQuestionSettings.pages.length; i++ ) {
@@ -136,7 +136,7 @@ var QSMQuestion;
136
  QSMQuestion.countTotal();
137
  },
138
  savePages: function() {
139
- QSMQuestion.displayAlert( 'Saving pages and questions...', 'info' );
140
  var pages = [];
141
 
142
  // Cycles through each page and add page + questions to pages variable
@@ -163,11 +163,11 @@ var QSMQuestion;
163
  data: data,
164
  method: 'POST',
165
  success: QSMQuestion.savePagesSuccess,
166
- error: QSMQuestion.displayjQueryError
167
  });
168
  },
169
  savePagesSuccess: function() {
170
- QSMQuestion.displayAlert( 'Questions and pages were saved!', 'success' );
171
  },
172
  addNewPage: function() {
173
  var template = wp.template( 'page' );
@@ -182,7 +182,7 @@ var QSMQuestion;
182
  setTimeout( QSMQuestion.removeNew, 250 );
183
  },
184
  addNewQuestion: function( model ) {
185
- QSMQuestion.displayAlert( 'Question created!', 'success' );
186
  QSMQuestion.addQuestionToPage( model );
187
  QSMQuestion.openEditPopup( model.id );
188
  QSMQuestion.countTotal();
@@ -206,7 +206,7 @@ var QSMQuestion;
206
  setTimeout( QSMQuestion.removeNew, 250 );
207
  },
208
  createQuestion: function( page ) {
209
- QSMQuestion.displayAlert( 'Creating question...', 'info' );
210
  QSMQuestion.questions.create(
211
  {
212
  quizID: qsmQuestionSettings.quizID,
@@ -215,12 +215,12 @@ var QSMQuestion;
215
  {
216
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
217
  success: QSMQuestion.addNewQuestion,
218
- error: QSMQuestion.displayError
219
  }
220
  );
221
  },
222
  duplicateQuestion: function( questionID ) {
223
- QSMQuestion.displayAlert( 'Duplicating question...', 'info' );
224
  var model = QSMQuestion.questions.get( questionID );
225
  var newModel = _.clone(model.attributes);
226
  newModel.id = null;
@@ -229,12 +229,12 @@ var QSMQuestion;
229
  {
230
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
231
  success: QSMQuestion.addNewQuestion,
232
- error: QSMQuestion.displayError
233
  }
234
  );
235
  },
236
  saveQuestion: function( questionID ) {
237
- QSMQuestion.displayAlert( 'Saving question...', 'info' );
238
  var model = QSMQuestion.questions.get( questionID );
239
  var hint = $( '#hint' ).val();
240
  var name = wp.editor.getContent( 'question-text' );
@@ -275,14 +275,14 @@ var QSMQuestion;
275
  {
276
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
277
  success: QSMQuestion.saveSuccess,
278
- error: QSMQuestion.displayError,
279
  type: 'POST'
280
  }
281
  );
282
  MicroModal.close('modal-1');
283
  },
284
  saveSuccess: function( model ) {
285
- QSMQuestion.displayAlert( 'Question was saved!', 'success' );
286
  var template = wp.template( 'question' );
287
  var page = model.get( 'page' ) + 1;
288
  $( '.question[data-question-id=' + model.id + ']' ).replaceWith( template( { id: model.id, type : model.get('type'), category : model.get('category'), question: model.get('name') } ) );
@@ -323,24 +323,6 @@ var QSMQuestion;
323
  }
324
  MicroModal.show( 'modal-1' );
325
  },
326
- displayjQueryError: function( jqXHR, textStatus, errorThrown ) {
327
- QSMQuestion.displayAlert( 'Error: ' + errorThrown + '! Please try again.', 'error' );
328
- },
329
- displayError: function( jqXHR, textStatus, errorThrown ) {
330
- QSMQuestion.displayAlert( 'Error: ' + errorThrown.errorThrown + '! Please try again.', 'error' );
331
- },
332
- displayAlert: function( message, type ) {
333
- QSMQuestion.clearAlerts();
334
- var template = wp.template( 'notice' );
335
- var data = {
336
- message: message,
337
- type: type
338
- };
339
- $( '.questions-messages' ).append( template( data ) );
340
- },
341
- clearAlerts: function() {
342
- $( '.questions-messages' ).empty();
343
- },
344
  removeNew: function() {
345
  $( '.page-new' ).removeClass( 'page-new' );
346
  $( '.question-new' ).removeClass( 'question-new' );
76
  },
77
  addQuestionFromQuestionBank: function( questionID ) {
78
  MicroModal.close( 'modal-2' );
79
+ QSMAdmin.displayAlert( 'Adding question...', 'info' );
80
  var model = new QSMQuestion.question( { id: questionID } );
81
  model.fetch({
82
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
83
  url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID,
84
  success: QSMQuestion.questionBankSuccess,
85
+ error: QSMAdmin.displayError
86
  });
87
  },
88
  questionBankSuccess: function( model ) {
89
  var page = parseInt( $( '#add-question-bank-page' ).val(), 10 );
90
  model.set( 'page', page );
91
+ QSMAdmin.displayAlert( 'Question added!', 'success' );
92
  QSMQuestion.questions.add( model );
93
  QSMQuestion.addQuestionToPage( model );
94
  },
112
  $( '#categories' ).prepend( template( { category: category } ) );
113
  },
114
  loadQuestions: function() {
115
+ QSMAdmin.displayAlert( 'Loading questions...', 'info' );
116
  QSMQuestion.questions.fetch({
117
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
118
  data: { quizID: qsmQuestionSettings.quizID },
119
  success: QSMQuestion.loadSuccess,
120
+ error: QSMAdmin.displayError
121
  });
122
  },
123
  loadSuccess: function() {
124
+ QSMAdmin.clearAlerts();
125
  var question;
126
  if ( qsmQuestionSettings.pages.length > 0 ) {
127
  for ( var i = 0; i < qsmQuestionSettings.pages.length; i++ ) {
136
  QSMQuestion.countTotal();
137
  },
138
  savePages: function() {
139
+ QSMAdmin.displayAlert( 'Saving pages and questions...', 'info' );
140
  var pages = [];
141
 
142
  // Cycles through each page and add page + questions to pages variable
163
  data: data,
164
  method: 'POST',
165
  success: QSMQuestion.savePagesSuccess,
166
+ error: QSMAdmin.displayjQueryError
167
  });
168
  },
169
  savePagesSuccess: function() {
170
+ QSMAdmin.displayAlert( 'Questions and pages were saved!', 'success' );
171
  },
172
  addNewPage: function() {
173
  var template = wp.template( 'page' );
182
  setTimeout( QSMQuestion.removeNew, 250 );
183
  },
184
  addNewQuestion: function( model ) {
185
+ QSMAdmin.displayAlert( 'Question created!', 'success' );
186
  QSMQuestion.addQuestionToPage( model );
187
  QSMQuestion.openEditPopup( model.id );
188
  QSMQuestion.countTotal();
206
  setTimeout( QSMQuestion.removeNew, 250 );
207
  },
208
  createQuestion: function( page ) {
209
+ QSMAdmin.displayAlert( 'Creating question...', 'info' );
210
  QSMQuestion.questions.create(
211
  {
212
  quizID: qsmQuestionSettings.quizID,
215
  {
216
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
217
  success: QSMQuestion.addNewQuestion,
218
+ error: QSMAdmin.displayError
219
  }
220
  );
221
  },
222
  duplicateQuestion: function( questionID ) {
223
+ QSMAdmin.displayAlert( 'Duplicating question...', 'info' );
224
  var model = QSMQuestion.questions.get( questionID );
225
  var newModel = _.clone(model.attributes);
226
  newModel.id = null;
229
  {
230
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
231
  success: QSMQuestion.addNewQuestion,
232
+ error: QSMAdmin.displayError
233
  }
234
  );
235
  },
236
  saveQuestion: function( questionID ) {
237
+ QSMAdmin.displayAlert( 'Saving question...', 'info' );
238
  var model = QSMQuestion.questions.get( questionID );
239
  var hint = $( '#hint' ).val();
240
  var name = wp.editor.getContent( 'question-text' );
275
  {
276
  headers: { 'X-WP-Nonce': qsmQuestionSettings.nonce },
277
  success: QSMQuestion.saveSuccess,
278
+ error: QSMAdmin.displayError,
279
  type: 'POST'
280
  }
281
  );
282
  MicroModal.close('modal-1');
283
  },
284
  saveSuccess: function( model ) {
285
+ QSMAdmin.displayAlert( 'Question was saved!', 'success' );
286
  var template = wp.template( 'question' );
287
  var page = model.get( 'page' ) + 1;
288
  $( '.question[data-question-id=' + model.id + ']' ).replaceWith( template( { id: model.id, type : model.get('type'), category : model.get('category'), question: model.get('name') } ) );
323
  }
324
  MicroModal.show( 'modal-1' );
325
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  removeNew: function() {
327
  $( '.page-new' ).removeClass( 'page-new' );
328
  $( '.question-new' ).removeClass( 'question-new' );
js/qsm-admin-results.js ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * QSM - Admin results pages
3
+ */
4
+
5
+ var QSMAdminResults;
6
+ (function ($) {
7
+ QSMAdminResults = {
8
+ total: 0,
9
+ saveResults: function() {
10
+ QSMAdmin.displayAlert( 'Saving results pages...', 'info' );
11
+ var pages = [];
12
+ var page = {};
13
+ var redirect_value = '';
14
+ $( '.results-page' ).each( function() {
15
+ page = {
16
+ 'conditions': [],
17
+ 'page': wp.editor.getContent( $( this ).find( '.results-page-template' ).attr( 'id' ) ),
18
+ 'redirect': false,
19
+ };
20
+ redirect_value = $( this ).find( '.results-page-redirect' ).val();
21
+ if ( '' != redirect_value ) {
22
+ page.redirect = redirect_value;
23
+ }
24
+ $( this ).find( '.results-page-condition' ).each( function() {
25
+ page.conditions.push({
26
+ 'criteria': $( this ).children( '.results-page-condition-criteria' ).val(),
27
+ 'operator': $( this ).children( '.results-page-condition-operator' ).val(),
28
+ 'value': $( this ).children( '.results-page-condition-value' ).val()
29
+ });
30
+ });
31
+ pages.push( page );
32
+ });
33
+ var data = {
34
+ 'pages': pages
35
+ }
36
+ $.ajax({
37
+ url: wpApiSettings.root + 'quiz-survey-master/v1/quizzes/' + qsmResultsObject.quizID + '/results',
38
+ method: 'POST',
39
+ data: data,
40
+ headers: { 'X-WP-Nonce': qsmResultsObject.nonce },
41
+ })
42
+ .done(function( results ) {
43
+ if ( results.status ) {
44
+ QSMAdmin.displayAlert( 'Results pages were saved!', 'success' );
45
+ } else {
46
+ QSMAdmin.displayAlert( 'There was an error when saving the results pages. Please try again.', 'error' );
47
+ }
48
+ })
49
+ .fail(QSMAdmin.displayjQueryError);
50
+ },
51
+ loadResults: function() {
52
+ QSMAdmin.displayAlert( 'Loading results pages...', 'info' );
53
+ $.ajax({
54
+ url: wpApiSettings.root + 'quiz-survey-master/v1/quizzes/' + qsmResultsObject.quizID + '/results',
55
+ headers: { 'X-WP-Nonce': qsmResultsObject.nonce },
56
+ })
57
+ .done(function( pages ) {
58
+ pages.forEach( function( page, i, pages ) {
59
+ QSMAdminResults.addResultsPage( page.conditions, page.page, page.redirect );
60
+ });
61
+ QSMAdmin.clearAlerts();
62
+ })
63
+ .fail(QSMAdmin.displayjQueryError);
64
+ },
65
+ addCondition: function( $page, criteria, operator, value ) {
66
+ var template = wp.template( 'results-page-condition' );
67
+ $page.find( '.results-page-when-conditions' ).append( template({
68
+ 'criteria': criteria,
69
+ 'operator': operator,
70
+ 'value': value
71
+ }));
72
+ },
73
+ newCondition: function( $page ) {
74
+ QSMAdminResults.addCondition( $page, 'score', 'equal', 0 );
75
+ },
76
+ addResultsPage: function( conditions, page, redirect ) {
77
+ QSMAdminResults.total += 1;
78
+ var template = wp.template( 'results-page' );
79
+ $( '#results-pages' ).append( template( { id: QSMAdminResults.total, page: page, redirect: redirect } ) );
80
+ conditions.forEach( function( condition, i, conditions) {
81
+ QSMAdminResults.addCondition(
82
+ $( '.results-page:last-child' ),
83
+ condition.criteria,
84
+ condition.operator,
85
+ condition.value
86
+ );
87
+ });
88
+ var settings = {
89
+ mediaButtons: true,
90
+ tinymce: {
91
+ forced_root_block : '',
92
+ toolbar1: 'formatselect,bold,italic,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,strikethrough,hr,forecolor,pastetext,removeformat,codeformat,charmap,undo,redo'
93
+ },
94
+ quicktags: true,
95
+ };
96
+ wp.editor.initialize( 'results-page-' + QSMAdminResults.total, settings );
97
+ },
98
+ newResultsPage: function() {
99
+ var conditions = [{
100
+ 'criteria': 'score',
101
+ 'operator': 'greater',
102
+ 'value': '0'
103
+ }];
104
+ var page = '%QUESTIONS_ANSWERS%';
105
+ QSMAdminResults.addResultsPage( conditions, page );
106
+ }
107
+ };
108
+ $(function() {
109
+ QSMAdminResults.loadResults();
110
+
111
+ $( '.add-new-page' ).on( 'click', function( event ) {
112
+ event.preventDefault();
113
+ QSMAdminResults.newResultsPage();
114
+ });
115
+ $( '.save-pages' ).on( 'click', function( event ) {
116
+ event.preventDefault();
117
+ QSMAdminResults.saveResults();
118
+ });
119
+ $( '#results-pages' ).on( 'click', '.new-condition', function( event ) {
120
+ event.preventDefault();
121
+ $page = $( this ).closest( '.results-page' );
122
+ QSMAdminResults.newCondition( $page );
123
+ });
124
+ $( '#results-pages' ).on( 'click', '.delete-page-button', function( event ) {
125
+ event.preventDefault();
126
+ $( this ).closest( '.results-page' ).remove();
127
+ });
128
+ $( '#results-pages' ).on( 'click', '.delete-condition-button', function( event ) {
129
+ event.preventDefault();
130
+ $( this ).closest( '.results-page-condition' ).remove();
131
+ });
132
+ });
133
+ }(jQuery));
js/qsm-admin.js CHANGED
@@ -4,19 +4,19 @@
4
 
5
  var QSMQuizzesSurveys;
6
  (function ($) {
7
- QSMQuizzesSurveys = {
8
- load: function() {
9
- if ( 0 !== qsmQuizObject.length ) {
10
- $.each( qsmQuizObject, function( i, val ) {
11
- QSMQuizzesSurveys.addQuizRow( val );
12
- });
13
- $( '#the-list tr' ).filter( ':even' ).addClass( 'alternate' );
14
- } else {
15
- var template = wp.template( 'no-quiz' );
16
- $( '.qsm-quizzes-page-content' ).hide();
17
- $( '#new_quiz_button' ).parent().after( template() );
18
- }
19
- },
20
  addQuizRow: function( quizData ) {
21
  var template = wp.template( 'quiz-row' );
22
  var values = {
4
 
5
  var QSMQuizzesSurveys;
6
  (function ($) {
7
+ QSMQuizzesSurveys = {
8
+ load: function() {
9
+ if ( 0 !== qsmQuizObject.length ) {
10
+ $.each( qsmQuizObject, function( i, val ) {
11
+ QSMQuizzesSurveys.addQuizRow( val );
12
+ });
13
+ $( '#the-list tr' ).filter( ':even' ).addClass( 'alternate' );
14
+ } else {
15
+ var template = wp.template( 'no-quiz' );
16
+ $( '.qsm-quizzes-page-content' ).hide();
17
+ $( '#new_quiz_button' ).parent().after( template() );
18
+ }
19
+ },
20
  addQuizRow: function( quizData ) {
21
  var template = wp.template( 'quiz-row' );
22
  var values = {
js/qsm-quiz.js CHANGED
@@ -479,7 +479,7 @@ function qsmDisplayLoading( $container ) {
479
  function qmnDisplayResults( results, quiz_form_id, $container ) {
480
  $container.empty();
481
  if ( results.redirect ) {
482
- window.location.replace( results.redirect_url );
483
  } else {
484
  $container.append( '<div class="qmn_results_page"></div>' );
485
  $container.find( '.qmn_results_page' ).html( results.display );
479
  function qmnDisplayResults( results, quiz_form_id, $container ) {
480
  $container.empty();
481
  if ( results.redirect ) {
482
+ window.location.replace( results.redirect );
483
  } else {
484
  $container.append( '<div class="qmn_results_page"></div>' );
485
  $container.find( '.qmn_results_page' ).html( results.display );
mlw_quizmaster2.php CHANGED
@@ -2,14 +2,14 @@
2
  /**
3
  * Plugin Name: Quiz And Survey Master
4
  * Description: Easily and quickly add quizzes and surveys to your website.
5
- * Version: 6.1.2
6
  * Author: Frank Corso
7
  * Author URI: https://www.quizandsurveymaster.com/
8
  * Plugin URI: https://www.quizandsurveymaster.com/
9
  * Text Domain: quiz-master-next
10
  *
11
  * @author Frank Corso
12
- * @version 6.1.2
13
  * @package QSM
14
  */
15
 
@@ -18,6 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
18
  }
19
 
20
  define( 'QSM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
 
21
  /**
22
  * This class is the main class of the plugin
23
  *
@@ -33,7 +34,7 @@ class MLWQuizMasterNext {
33
  * @var string
34
  * @since 4.0.0
35
  */
36
- public $version = '6.1.2';
37
 
38
  /**
39
  * QSM Alert Manager Object
@@ -142,6 +143,8 @@ class MLWQuizMasterNext {
142
  }
143
  include 'php/classes/class-qsm-questions.php';
144
  include 'php/classes/class-qsm-contact-manager.php';
 
 
145
  include 'php/classes/class-qmn-quiz-manager.php';
146
 
147
  include 'php/template-variables.php';
@@ -270,18 +273,11 @@ class MLWQuizMasterNext {
270
  add_submenu_page( __FILE__, __( 'Results', 'quiz-master-next' ), __( 'Results', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_results', 'qsm_generate_admin_results_page' );
271
  add_submenu_page( __FILE__, __( 'Result Details', 'quiz-master-next' ), __( 'Result Details', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_result_details', 'qsm_generate_result_details' );
272
  add_submenu_page( __FILE__, __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), 'manage_options', 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) );
273
- add_submenu_page( __FILE__, __( 'Tools', 'quiz-master-next' ), __( 'Tools', 'quiz-master-next' ), 'manage_options', 'mlw_quiz_tools', 'mlw_generate_quiz_tools' );
274
  add_submenu_page( __FILE__, __( 'Stats', 'quiz-master-next' ), __( 'Stats', 'quiz-master-next' ), 'moderate_comments', 'qmn_stats', 'qmn_generate_stats_page' );
275
  add_submenu_page( __FILE__, __( 'Addon Settings', 'quiz-master-next' ), __( 'Addon Settings', 'quiz-master-next' ), 'moderate_comments', 'qmn_addons', 'qmn_addons_page' );
276
- add_submenu_page( __FILE__, __( 'Help', 'quiz-master-next' ), __( 'Help', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_help', 'mlw_generate_help_page' );
277
-
278
- add_dashboard_page(
279
- __( 'QSM About', 'quiz-master-next' ),
280
- __( 'QSM About', 'quiz-master-next' ),
281
- 'manage_options',
282
- 'qsm_about',
283
- 'mlw_generate_about_page'
284
- );
285
  }
286
  }
287
 
@@ -294,7 +290,6 @@ class MLWQuizMasterNext {
294
  * @return void
295
  */
296
  public function admin_head() {
297
- remove_submenu_page( 'index.php', 'qsm_about' );
298
  remove_submenu_page( 'quiz-master-next/mlw_quizmaster2.php', 'mlw_quiz_options' );
299
  remove_submenu_page( 'quiz-master-next/mlw_quizmaster2.php', 'qsm_quiz_result_details' );
300
  }
2
  /**
3
  * Plugin Name: Quiz And Survey Master
4
  * Description: Easily and quickly add quizzes and surveys to your website.
5
+ * Version: 6.2.0
6
  * Author: Frank Corso
7
  * Author URI: https://www.quizandsurveymaster.com/
8
  * Plugin URI: https://www.quizandsurveymaster.com/
9
  * Text Domain: quiz-master-next
10
  *
11
  * @author Frank Corso
12
+ * @version 6.2.0
13
  * @package QSM
14
  */
15
 
18
  }
19
 
20
  define( 'QSM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
21
+
22
  /**
23
  * This class is the main class of the plugin
24
  *
34
  * @var string
35
  * @since 4.0.0
36
  */
37
+ public $version = '6.2.0';
38
 
39
  /**
40
  * QSM Alert Manager Object
143
  }
144
  include 'php/classes/class-qsm-questions.php';
145
  include 'php/classes/class-qsm-contact-manager.php';
146
+ include 'php/classes/class-qsm-results-pages.php';
147
+ include 'php/classes/class-qsm-emails.php';
148
  include 'php/classes/class-qmn-quiz-manager.php';
149
 
150
  include 'php/template-variables.php';
273
  add_submenu_page( __FILE__, __( 'Results', 'quiz-master-next' ), __( 'Results', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_results', 'qsm_generate_admin_results_page' );
274
  add_submenu_page( __FILE__, __( 'Result Details', 'quiz-master-next' ), __( 'Result Details', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_result_details', 'qsm_generate_result_details' );
275
  add_submenu_page( __FILE__, __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), 'manage_options', 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) );
276
+ add_submenu_page( __FILE__, __( 'Tools', 'quiz-master-next' ), __( 'Tools', 'quiz-master-next' ), 'manage_options', 'qsm_quiz_tools', 'qsm_generate_quiz_tools' );
277
  add_submenu_page( __FILE__, __( 'Stats', 'quiz-master-next' ), __( 'Stats', 'quiz-master-next' ), 'moderate_comments', 'qmn_stats', 'qmn_generate_stats_page' );
278
  add_submenu_page( __FILE__, __( 'Addon Settings', 'quiz-master-next' ), __( 'Addon Settings', 'quiz-master-next' ), 'moderate_comments', 'qmn_addons', 'qmn_addons_page' );
279
+ add_submenu_page( __FILE__, __( 'QSM About', 'quiz-master-next' ), __( 'QSM About', 'quiz-master-next' ), 'moderate_comments', 'qsm_about_page', 'qsm_generate_about_page' );
280
+ add_submenu_page( __FILE__, __( 'Help', 'quiz-master-next' ), __( 'Help', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_help', 'qsm_generate_help_page' );
 
 
 
 
 
 
 
281
  }
282
  }
283
 
290
  * @return void
291
  */
292
  public function admin_head() {
 
293
  remove_submenu_page( 'quiz-master-next/mlw_quizmaster2.php', 'mlw_quiz_options' );
294
  remove_submenu_page( 'quiz-master-next/mlw_quizmaster2.php', 'qsm_quiz_result_details' );
295
  }
php/admin/about-page.php CHANGED
@@ -1,18 +1,24 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
3
 
4
  /**
5
  * This function shows the about page. It also shows the changelog information.
6
  *
7
  * @return void
8
- * @since 4.4.0
9
  */
10
- function mlw_generate_about_page() {
11
 
12
  global $mlwQuizMasterNext;
13
  $version = $mlwQuizMasterNext->version;
14
- wp_enqueue_style( 'qsm_admin_style', plugins_url( '../../css/qsm-admin.css' , __FILE__ ), array(), $version );
15
- wp_enqueue_script( 'qsm_admin_js', plugins_url( '../../js/admin.js' , __FILE__ ), array( 'jquery' ), $version );
16
  ?>
17
  <style>
18
  div.qsm_icon_wrap {
@@ -20,33 +26,33 @@ function mlw_generate_about_page() {
20
  }
21
  </style>
22
  <div class="wrap about-wrap">
23
- <h1><?php _e( 'Welcome To Quiz And Survey Master (Formerly Quiz Master Next)', 'quiz-master-next' ); ?></h1>
24
- <div class="about-text"><?php _e( 'Thank you for updating!', 'quiz-master-next' ); ?></div>
25
- <div class="qsm_icon_wrap"><?php echo $version; ?></div>
26
  <h2 class="nav-tab-wrapper">
27
  <a href="#" data-tab='1' class="nav-tab nav-tab-active qsm-tab">
28
- <?php _e( "What's New!", 'quiz-master-next' ); ?></a>
29
  <a href="#" data-tab='2' class="nav-tab qsm-tab">
30
- <?php _e( 'Changelog', 'quiz-master-next' ); ?></a>
31
  <a href="#" data-tab='3' class="nav-tab qsm-tab">
32
- <?php _e( 'People Who Make QSM Possible', 'quiz-master-next' ); ?></a>
33
  </h2>
34
  <div class="qsm-tab-content tab-1">
35
  <div class="feature">
36
- <h2 class="feature-headline">Welcome to QSM 6.0!</h2>
37
  </div>
38
  <div class="feature">
39
- <h2 class="feature-headline">New PHP Minimum</h2>
40
- <p class="feature-text">As planned, all versions of Quiz And Survey Master starting with this version will require a minimum of PHP 5.4.</p>
41
  </div>
42
  <div class="feature">
43
- <h2 class="feature-headline">Removing Of Deprecated Features</h2>
44
- <p class="feature-text">As planned, the Leaderboards is now in our free addon instead of being built into the main plugin. The old "Tools" tab has also been removed.</p>
45
  </div>
46
  </div>
47
  <div class="qsm-tab-content tab-2" style="display: none;">
48
  <h2>Changelog</h2>
49
- <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 57 ); ?>
50
  </div>
51
  <div class="qsm-tab-content tab-3" style="display:none;">
52
  <h2>GitHub Contributors</h2>
1
  <?php
2
+ /**
3
+ * Generates the content for the about page.
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
 
10
  /**
11
  * This function shows the about page. It also shows the changelog information.
12
  *
13
  * @return void
14
+ * @since 6.2.0
15
  */
16
+ function qsm_generate_about_page() {
17
 
18
  global $mlwQuizMasterNext;
19
  $version = $mlwQuizMasterNext->version;
20
+ wp_enqueue_style( 'qsm_admin_style', plugins_url( '../../css/qsm-admin.css', __FILE__ ), array(), $version );
21
+ wp_enqueue_script( 'qsm_admin_js', plugins_url( '../../js/admin.js', __FILE__ ), array( 'jquery' ), $version );
22
  ?>
23
  <style>
24
  div.qsm_icon_wrap {
26
  }
27
  </style>
28
  <div class="wrap about-wrap">
29
+ <h1><?php esc_html_e( 'Welcome To Quiz And Survey Master (Formerly Quiz Master Next)', 'quiz-master-next' ); ?></h1>
30
+ <div class="about-text"><?php esc_html_e( 'Thank you for updating!', 'quiz-master-next' ); ?></div>
31
+ <div class="qsm_icon_wrap"><?php echo esc_html( $version ); ?></div>
32
  <h2 class="nav-tab-wrapper">
33
  <a href="#" data-tab='1' class="nav-tab nav-tab-active qsm-tab">
34
+ <?php esc_html_e( "What's New!", 'quiz-master-next' ); ?></a>
35
  <a href="#" data-tab='2' class="nav-tab qsm-tab">
36
+ <?php esc_html_e( 'Changelog', 'quiz-master-next' ); ?></a>
37
  <a href="#" data-tab='3' class="nav-tab qsm-tab">
38
+ <?php esc_html_e( 'People Who Make QSM Possible', 'quiz-master-next' ); ?></a>
39
  </h2>
40
  <div class="qsm-tab-content tab-1">
41
  <div class="feature">
42
+ <h2 class="feature-headline">Welcome to QSM 6.2!</h2>
43
  </div>
44
  <div class="feature">
45
+ <h2 class="feature-headline">New Email System</h2>
46
+ <p class="feature-text">All of the email system has been entirely re-written. The newer system is much more intuitive and allows for more granular conditions allowing us to add in more conditions types in future versions.</p>
47
  </div>
48
  <div class="feature">
49
+ <h2 class="feature-headline">New Results Page System</h2>
50
+ <p class="feature-text">All of the results page has been entirely re-written. The newer system is much more intuitive and allows for more granular conditions allowing us to add in more conditions types in future versions.</p>
51
  </div>
52
  </div>
53
  <div class="qsm-tab-content tab-2" style="display: none;">
54
  <h2>Changelog</h2>
55
+ <?php QSM_Changelog_Generator::get_changelog_list( 'fpcorso/quiz_master_next', 56 ); ?>
56
  </div>
57
  <div class="qsm-tab-content tab-3" style="display:none;">
58
  <h2>GitHub Contributors</h2>
php/admin/admin-results-page.php CHANGED
@@ -23,7 +23,7 @@ function qsm_generate_admin_results_page() {
23
  <div class="wrap">
24
  <h2><?php _e('Quiz Results', 'quiz-master-next'); ?></h2>
25
  <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
26
- <?php echo mlw_qmn_show_adverts(); ?>
27
  <h2 class="nav-tab-wrapper">
28
  <?php
29
  // Cycles through the tabs and creates the navigation
23
  <div class="wrap">
24
  <h2><?php _e('Quiz Results', 'quiz-master-next'); ?></h2>
25
  <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
26
+ <?php qsm_show_adverts(); ?>
27
  <h2 class="nav-tab-wrapper">
28
  <?php
29
  // Cycles through the tabs and creates the navigation
php/admin/help-page.php CHANGED
@@ -13,9 +13,9 @@ if ( ! defined( 'ABSPATH' ) ) {
13
  * This function generates the help page.
14
  *
15
  * @return void
16
- * @since 4.4.0
17
  */
18
- function mlw_generate_help_page() {
19
  if ( ! current_user_can( 'moderate_comments' ) ) {
20
  return;
21
  }
@@ -27,17 +27,17 @@ function mlw_generate_help_page() {
27
  add_meta_box( 'wpss_mrts', __( 'System Info', 'quiz-master-next' ), 'qsm_system_meta_box_content', 'meta_box_sys_info' );
28
  ?>
29
  <div class="wrap">
30
- <h2><?php esc_html_e( 'Help Page', 'quiz-master-next' ); ?></h2>
31
- <?php echo mlw_qmn_show_adverts(); ?>
32
 
33
- <!--Display Widget Boxes-->
34
- <div style="width:100%;" class="inner-sidebar1">
35
- <?php do_meta_boxes( 'meta_box_help', 'advanced', '' ); ?>
36
- </div>
37
 
38
- <div style="width:100%;" class="inner-sidebar1">
39
- <?php do_meta_boxes( 'meta_box_sys_info', 'advanced', '' ); ?>
40
- </div>
41
 
42
  </div>
43
  <?php
@@ -79,83 +79,85 @@ function qsm_get_system_info() {
79
  global $wpdb;
80
  global $mlwQuizMasterNext;
81
 
82
- $sys_info = "";
83
 
84
- $theme_data = wp_get_theme();
85
- $theme = $theme_data->Name . ' ' . $theme_data->Version;
86
  $parent_theme = $theme_data->Template;
87
  if ( ! empty( $parent_theme ) ) {
88
  $parent_theme_data = wp_get_theme( $parent_theme );
89
  $parent_theme = $parent_theme_data->Name . ' ' . $parent_theme_data->Version;
90
  }
91
 
92
- $sys_info .= "<h3>Site Information</h3><br />";
93
- $sys_info .= "Site URL: ".site_url()."<br />";
94
- $sys_info .= "Home URL: ".home_url()."<br />";
95
- $sys_info .= "Multisite: ".( is_multisite() ? 'Yes' : 'No' )."<br />";
96
 
97
- $sys_info .= "<h3>WordPress Information</h3><br />";
98
- $sys_info .= "Version: ".get_bloginfo( 'version' )."<br />";
99
- $sys_info .= "Language: ".( defined( 'WPLANG' ) && WPLANG ? WPLANG : 'en_US' )."<br />";
100
  $sys_info .= 'Permalink Structure: ' . ( get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : 'Default' ) . '<br>';
101
- $sys_info .= "Active Theme: ".$theme."<br />";
102
  $sys_info .= "Parent Theme: {$parent_theme}<br>";
103
- $sys_info .= "Debug Mode: ".( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' )."<br />";
104
- $sys_info .= "Memory Limit: ".WP_MEMORY_LIMIT."<br />";
105
 
106
- $sys_info .= "<h3>Plugins Information</h3><br />";
107
  $plugin_mu = get_mu_plugins();
108
  if ( count( $plugin_mu ) > 0 ) {
109
- $sys_info .= "<h4>Must Use</h4><br />";
110
  foreach ( $plugin_mu as $plugin => $plugin_data ) {
111
  $sys_info .= $plugin_data['Name'] . ': ' . $plugin_data['Version'] . "<br />";
112
  }
113
  }
114
- $sys_info .= "<h4>Active</h4><br />";
115
- $plugins = get_plugins();
116
  $active_plugins = get_option( 'active_plugins', array() );
117
- foreach( $plugins as $plugin_path => $plugin ) {
118
- if( !in_array( $plugin_path, $active_plugins ) )
119
  continue;
120
- $sys_info .= $plugin['Name'] . ': ' . $plugin['Version'] . "<br />";
 
121
  }
122
- $sys_info .= "<h4>Inactive</h4><br />";
123
- foreach( $plugins as $plugin_path => $plugin ) {
124
- if( in_array( $plugin_path, $active_plugins ) )
125
  continue;
126
- $sys_info .= $plugin['Name'] . ': ' . $plugin['Version'] . "<br />";
 
127
  }
128
 
129
- $sys_info .= "<h3>Server Information</h3><br />";
130
- $sys_info .= "PHP : ".PHP_VERSION."<br />";
131
- $sys_info .= "MySQL : ".$wpdb->db_version()."<br />";
132
- $sys_info .= "Webserver : ".$_SERVER['SERVER_SOFTWARE']."<br />";
133
-
134
- $mlw_stat_total_quiz = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_quizzes LIMIT 1" );
135
- $mlw_stat_total_active_quiz = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_quizzes WHERE deleted=0 LIMIT 1" );
136
- $mlw_stat_total_questions = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_questions LIMIT 1" );
137
- $mlw_stat_total_active_questions = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_questions WHERE deleted=0 LIMIT 1" );
138
- $total_results = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_results LIMIT 1" );
139
- $total_active_results = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."mlw_results WHERE deleted=0 LIMIT 1" );
140
-
141
- $sys_info .= "<h3>QSM Information</h3><br />";
142
- $sys_info .= "Initial Version : ".get_option('qmn_original_version')."<br />";
143
- $sys_info .= "Current Version : ".$mlwQuizMasterNext->version."<br />";
144
- $sys_info .= "Total Quizzes : ".$mlw_stat_total_quiz."<br />";
145
- $sys_info .= "Total Active Quizzes : ".$mlw_stat_total_active_quiz."<br />";
146
- $sys_info .= "Total Questions : ".$mlw_stat_total_questions."<br />";
147
- $sys_info .= "Total Active Questions : ".$mlw_stat_total_active_questions."<br />";
148
- $sys_info .= "Total Results : ".$total_results."<br />";
149
- $sys_info .= "Total Active Results : ".$total_active_results."<br />";
150
-
151
- $sys_info .= "<h3>QSM Recent Logs</h3><br />";
152
  $recent_errors = $mlwQuizMasterNext->log_manager->get_logs();
153
  if ( $recent_errors ) {
154
- foreach( $recent_errors as $error ) {
155
- $sys_info .= "Log created at ". $error->post_date . " : " . $error->post_title . " - " . $error->post_content . "<br />";
156
  }
157
  } else {
158
- $sys_info .= "No recent logs<br />";
159
  }
160
 
161
  return $sys_info;
13
  * This function generates the help page.
14
  *
15
  * @return void
16
+ * @since 6.2.0
17
  */
18
+ function qsm_generate_help_page() {
19
  if ( ! current_user_can( 'moderate_comments' ) ) {
20
  return;
21
  }
27
  add_meta_box( 'wpss_mrts', __( 'System Info', 'quiz-master-next' ), 'qsm_system_meta_box_content', 'meta_box_sys_info' );
28
  ?>
29
  <div class="wrap">
30
+ <h2><?php esc_html_e( 'Help Page', 'quiz-master-next' ); ?></h2>
31
+ <?php qsm_show_adverts(); ?>
32
 
33
+ <!--Display Widget Boxes-->
34
+ <div style="width:100%;" class="inner-sidebar1">
35
+ <?php do_meta_boxes( 'meta_box_help', 'advanced', '' ); ?>
36
+ </div>
37
 
38
+ <div style="width:100%;" class="inner-sidebar1">
39
+ <?php do_meta_boxes( 'meta_box_sys_info', 'advanced', '' ); ?>
40
+ </div>
41
 
42
  </div>
43
  <?php
79
  global $wpdb;
80
  global $mlwQuizMasterNext;
81
 
82
+ $sys_info = '';
83
 
84
+ $theme_data = wp_get_theme();
85
+ $theme = $theme_data->Name . ' ' . $theme_data->Version;
86
  $parent_theme = $theme_data->Template;
87
  if ( ! empty( $parent_theme ) ) {
88
  $parent_theme_data = wp_get_theme( $parent_theme );
89
  $parent_theme = $parent_theme_data->Name . ' ' . $parent_theme_data->Version;
90
  }
91
 
92
+ $sys_info .= '<h3>Site Information</h3><br />';
93
+ $sys_info .= 'Site URL: ' . site_url() . '<br />';
94
+ $sys_info .= 'Home URL: ' . home_url() . '<br />';
95
+ $sys_info .= 'Multisite: ' . ( is_multisite() ? 'Yes' : 'No' ) . '<br />';
96
 
97
+ $sys_info .= '<h3>WordPress Information</h3><br />';
98
+ $sys_info .= 'Version: ' . get_bloginfo( 'version' ) . '<br />';
99
+ $sys_info .= 'Language: ' . ( defined( 'WPLANG' ) && WPLANG ? WPLANG : 'en_US' ) . '<br />';
100
  $sys_info .= 'Permalink Structure: ' . ( get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : 'Default' ) . '<br>';
101
+ $sys_info .= "Active Theme: {$theme}<br />";
102
  $sys_info .= "Parent Theme: {$parent_theme}<br>";
103
+ $sys_info .= 'Debug Mode: ' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ) . '<br />';
104
+ $sys_info .= 'Memory Limit: ' . WP_MEMORY_LIMIT . '<br />';
105
 
106
+ $sys_info .= '<h3>Plugins Information</h3><br />';
107
  $plugin_mu = get_mu_plugins();
108
  if ( count( $plugin_mu ) > 0 ) {
109
+ $sys_info .= '<h4>Must Use</h4><br />';
110
  foreach ( $plugin_mu as $plugin => $plugin_data ) {
111
  $sys_info .= $plugin_data['Name'] . ': ' . $plugin_data['Version'] . "<br />";
112
  }
113
  }
114
+ $sys_info .= '<h4>Active</h4><br />';
115
+ $plugins = get_plugins();
116
  $active_plugins = get_option( 'active_plugins', array() );
117
+ foreach ( $plugins as $plugin_path => $plugin ) {
118
+ if ( ! in_array( $plugin_path, $active_plugins ) ) {
119
  continue;
120
+ }
121
+ $sys_info .= $plugin['Name'] . ': ' . $plugin['Version'] . '<br />';
122
  }
123
+ $sys_info .= '<h4>Inactive</h4><br />';
124
+ foreach ( $plugins as $plugin_path => $plugin ) {
125
+ if ( in_array( $plugin_path, $active_plugins ) ) {
126
  continue;
127
+ }
128
+ $sys_info .= $plugin['Name'] . ': ' . $plugin['Version'] . '<br />';
129
  }
130
 
131
+ $sys_info .= '<h3>Server Information</h3><br />';
132
+ $sys_info .= 'PHP : ' . PHP_VERSION . '<br />';
133
+ $sys_info .= 'MySQL : ' . $wpdb->db_version() . '<br />';
134
+ $sys_info .= 'Webserver : ' . $_SERVER['SERVER_SOFTWARE'] . '<br />';
135
+
136
+ $total_quizzes = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_quizzes LIMIT 1" );
137
+ $total_active_quizzes = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_quizzes WHERE deleted = 0 LIMIT 1" );
138
+ $total_questions = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_questions LIMIT 1" );
139
+ $total_active_questions = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_questions WHERE deleted = 0 LIMIT 1" );
140
+ $total_results = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results LIMIT 1" );
141
+ $total_active_results = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mlw_results WHERE deleted = 0 LIMIT 1" );
142
+
143
+ $sys_info .= '<h3>QSM Information</h3><br />';
144
+ $sys_info .= 'Initial Version : ' . get_option( 'qmn_original_version' ) . '<br />';
145
+ $sys_info .= 'Current Version : ' . $mlwQuizMasterNext->version . '<br />';
146
+ $sys_info .= "Total Quizzes : {$total_quizzes}<br />";
147
+ $sys_info .= "Total Active Quizzes : {$total_active_quizzes}<br />";
148
+ $sys_info .= "Total Questions : {$total_questions}<br />";
149
+ $sys_info .= "Total Active Questions : {$total_active_questions}<br />";
150
+ $sys_info .= "Total Results : {$total_results}<br />";
151
+ $sys_info .= "Total Active Results : {$total_active_results}<br />";
152
+
153
+ $sys_info .= '<h3>QSM Recent Logs</h3><br />';
154
  $recent_errors = $mlwQuizMasterNext->log_manager->get_logs();
155
  if ( $recent_errors ) {
156
+ foreach ( $recent_errors as $error ) {
157
+ $sys_info .= "Log created at {$error->post_date}: {$error->post_title} - {$error->post_content}<br />";
158
  }
159
  } else {
160
+ $sys_info .= 'No recent logs<br />';
161
  }
162
 
163
  return $sys_info;
php/admin/options-page-email-tab.php CHANGED
@@ -1,17 +1,25 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
 
 
3
 
4
  /**
5
  * Creates the email tab in the Quiz Settings Page
6
  *
7
  * @return void
8
- * @since 4.4.0
9
  */
10
- function qmn_settings_email_tab() {
11
  global $mlwQuizMasterNext;
12
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Emails', 'quiz-master-next'), 'qsm_options_emails_tab_content' );
13
  }
14
- add_action( 'plugins_loaded', 'qmn_settings_email_tab', 5 );
15
 
16
  /**
17
  * Creates the email content that is displayed on the email tab.
@@ -22,255 +30,22 @@ add_action( 'plugins_loaded', 'qmn_settings_email_tab', 5 );
22
  function qsm_options_emails_tab_content() {
23
  global $wpdb;
24
  global $mlwQuizMasterNext;
25
- $quiz_id = $_GET['quiz_id'];
26
- // Checks to add new user email template.
27
- if ( isset( $_POST["mlw_add_email_page"] ) && $_POST["mlw_add_email_page"] == "confirmation" ) {
28
- //Function variables
29
- $mlw_qmn_add_email_id = intval($_POST["mlw_add_email_quiz_id"]);
30
- $mlw_qmn_user_email = $wpdb->get_var( $wpdb->prepare( "SELECT user_email_template FROM ".$wpdb->prefix."mlw_quizzes WHERE quiz_id=%d", $mlw_qmn_add_email_id ) );
31
-
32
- //Load user email and check if it is array already. If not, turn it into one
33
- if ( is_serialized( $mlw_qmn_user_email ) && is_array( @unserialize( $mlw_qmn_user_email ) ) ) {
34
- $mlw_qmn_email_array = @unserialize($mlw_qmn_user_email);
35
- $mlw_new_landing_array = array(0, 100, 'Enter Your Text Here', 'Quiz Results For %QUIZ_NAME%');
36
- array_unshift($mlw_qmn_email_array , $mlw_new_landing_array);
37
- $mlw_qmn_email_array = serialize($mlw_qmn_email_array);
38
-
39
- } else {
40
- $mlw_qmn_email_array = array(array(0, 0, $mlw_qmn_user_email, 'Quiz Results For %QUIZ_NAME%'));
41
- $mlw_new_landing_array = array(0, 100, 'Enter Your Text Here', 'Quiz Results For %QUIZ_NAME%');
42
- array_unshift($mlw_qmn_email_array , $mlw_new_landing_array);
43
- $mlw_qmn_email_array = serialize($mlw_qmn_email_array);
44
- }
45
- // Update email template with new array then check to see if worked.
46
- $mlw_new_email_results = $wpdb->query( $wpdb->prepare( "UPDATE ".$wpdb->prefix."mlw_quizzes SET user_email_template='%s', last_activity='".date("Y-m-d H:i:s")."' WHERE quiz_id=%d", $mlw_qmn_email_array, $mlw_qmn_add_email_id ) );
47
- if ( false !== $mlw_new_email_results ) {
48
- $mlwQuizMasterNext->alertManager->newAlert(__('The email has been added successfully.', 'quiz-master-next'), 'success');
49
- $mlwQuizMasterNext->audit_manager->new_audit( "New User Email Has Been Created For Quiz Number $mlw_qmn_add_email_id" );
50
- } else {
51
- $error = $wpdb->last_error;
52
- if ( empty( $error ) ) {
53
- $error = __( 'Unknown error', 'quiz-master-next' );
54
- }
55
- $mlwQuizMasterNext->alertManager->newAlert( sprintf( __( 'There has been an error in this action. Please try again. Error from WordPress: %s', 'quiz-master-next'), $error ), 'error' );
56
- $mlwQuizMasterNext->log_manager->add( 'Error creating new user email', "Tried {$wpdb->last_query} but got $error.", 0, 'error');
57
- }
58
- }
59
-
60
- // Checks to add new admin email template.
61
- if (isset($_POST["mlw_add_admin_email_page"]) && $_POST["mlw_add_admin_email_page"] == "confirmation")
62
- {
63
- //Function variables
64
- $mlw_qmn_add_email_id = intval($_POST["mlw_add_admin_email_quiz_id"]);
65
- $mlw_qmn_admin_email = $wpdb->get_var( $wpdb->prepare( "SELECT admin_email_template FROM ".$wpdb->prefix."mlw_quizzes WHERE quiz_id=%d", $mlw_qmn_add_email_id ) );
66
-
67
- //Load user email and check if it is array already. If not, turn it into one
68
- if (is_serialized($mlw_qmn_admin_email) && is_array(@unserialize($mlw_qmn_admin_email)))
69
- {
70
- $mlw_qmn_email_array = @unserialize($mlw_qmn_admin_email);
71
- $mlw_new_landing_array = array(
72
- "begin_score" => 0,
73
- "end_score" => 100,
74
- "message" => __('Enter text here', 'quiz-master-next'),
75
- "subject" => 'Quiz Results For %QUIZ_NAME%'
76
- );
77
- array_unshift($mlw_qmn_email_array , $mlw_new_landing_array);
78
- $mlw_qmn_email_array = serialize($mlw_qmn_email_array);
79
-
80
- }
81
- else
82
- {
83
- $mlw_qmn_email_array = array(array(
84
- "begin_score" => 0,
85
- "end_score" => 0,
86
- "message" => $mlw_qmn_admin_email,
87
- "subject" => 'Quiz Results For %QUIZ_NAME%'
88
- ));
89
- $mlw_new_landing_array = array(
90
- "begin_score" => 0,
91
- "end_score" => 100,
92
- "message" => __('Enter text here', 'quiz-master-next'),
93
- "subject" => 'Quiz Results For %QUIZ_NAME%'
94
- );
95
- array_unshift($mlw_qmn_email_array , $mlw_new_landing_array);
96
- $mlw_qmn_email_array = serialize($mlw_qmn_email_array);
97
- }
98
- //Update email template with new array then check to see if worked
99
- $mlw_new_email_results = $wpdb->query( $wpdb->prepare( "UPDATE ".$wpdb->prefix."mlw_quizzes SET admin_email_template='%s', last_activity='".date("Y-m-d H:i:s")."' WHERE quiz_id=%d", $mlw_qmn_email_array, $mlw_qmn_add_email_id ) );
100
- if ( false != $mlw_new_email_results ) {
101
- $mlwQuizMasterNext->alertManager->newAlert(__('The email has been added successfully.', 'quiz-master-next'), 'success');
102
- $mlwQuizMasterNext->audit_manager->new_audit( "New Admin Email Has Been Created For Quiz Number $mlw_qmn_add_email_id" );
103
- }
104
- else
105
- {
106
- $mlwQuizMasterNext->alertManager->newAlert(sprintf(__('There has been an error in this action. Please share this with the developer. Error Code: %s', 'quiz-master-next'), '0016'), 'error');
107
- $mlwQuizMasterNext->log_manager->add("Error 0016", $wpdb->last_error.' from '.$wpdb->last_query, 0, 'error');
108
- }
109
- }
110
-
111
- //Check to save email templates
112
- if (isset($_POST["mlw_save_email_template"]) && $_POST["mlw_save_email_template"] == "confirmation")
113
- {
114
- //Function Variables
115
- $mlw_qmn_email_id = intval($_POST["mlw_email_quiz_id"]);
116
- $mlw_qmn_email_template_total = intval($_POST["mlw_email_template_total"]);
117
- $mlw_qmn_email_admin_total = intval($_POST["mlw_email_admin_total"]);
118
- $mlw_send_user_email = intval( $_POST["sendUserEmail"] );
119
- $mlw_send_admin_email = intval( $_POST["sendAdminEmail"] );
120
- $mlw_admin_email = sanitize_text_field( $_POST["adminEmail"] );
121
- $mlw_email_from_text = sanitize_text_field( $_POST["emailFromText"] );
122
- $from_address = sanitize_text_field( $_POST["emailFromAddress"] );
123
- $reply_to_user = sanitize_text_field( $_POST["replyToUser"] );
124
-
125
- //from email array
126
- $from_email_array = array(
127
- 'from_name' => $mlw_email_from_text,
128
- 'from_email' => $from_address,
129
- 'reply_to' => $reply_to_user
130
- );
131
-
132
- //Create new array
133
- $i = 1;
134
- $mlw_qmn_new_email_array = array();
135
- while ( $i <= $mlw_qmn_email_template_total ) {
136
- if ( $_POST["user_email_".$i] != "Delete" ) {
137
- $mlw_qmn_email_each = array(intval($_POST["user_email_begin_".$i]), intval($_POST["user_email_end_".$i]), htmlspecialchars(stripslashes($_POST["user_email_".$i]), ENT_QUOTES), htmlspecialchars(stripslashes($_POST["user_email_subject_".$i]), ENT_QUOTES));
138
- $mlw_qmn_new_email_array[] = $mlw_qmn_email_each;
139
- }
140
- $i++;
141
- }
142
-
143
- //Create new array
144
- $i = 1;
145
- $mlw_qmn_new_admin_array = array();
146
- while ($i <= $mlw_qmn_email_admin_total)
147
- {
148
- if ($_POST["admin_email_".$i] != "Delete")
149
- {
150
- $mlw_qmn_email_each = array(
151
- "begin_score" => intval($_POST["admin_email_begin_".$i]),
152
- "end_score" => intval($_POST["admin_email_end_".$i]),
153
- "message" => htmlspecialchars(stripslashes($_POST["admin_email_".$i]), ENT_QUOTES),
154
- "subject" => htmlspecialchars(stripslashes($_POST["admin_email_subject_".$i]), ENT_QUOTES)
155
- );
156
- $mlw_qmn_new_admin_array[] = $mlw_qmn_email_each;
157
- }
158
- $i++;
159
- }
160
-
161
- $from_email_array = serialize( $from_email_array );
162
- $mlw_qmn_new_email_array = serialize($mlw_qmn_new_email_array);
163
- $mlw_qmn_new_admin_array = serialize($mlw_qmn_new_admin_array);
164
-
165
- $mlw_new_email_results = $wpdb->update(
166
- $wpdb->prefix . "mlw_quizzes",
167
- array(
168
- 'send_user_email' => $mlw_send_user_email,
169
- 'send_admin_email' => $mlw_send_admin_email,
170
- 'admin_email' => $mlw_admin_email,
171
- 'email_from_text' => $from_email_array,
172
- 'user_email_template' => $mlw_qmn_new_email_array,
173
- 'admin_email_template' => $mlw_qmn_new_admin_array,
174
- 'last_activity' => date("Y-m-d H:i:s")
175
- ),
176
- array( 'quiz_id' => $mlw_qmn_email_id ),
177
- array(
178
- '%s',
179
- '%s',
180
- '%s',
181
- '%s',
182
- '%s',
183
- '%s',
184
- '%s'
185
- ),
186
- array( '%d' )
187
- );
188
- if ( false != $mlw_new_email_results ) {
189
- $mlwQuizMasterNext->alertManager->newAlert( __( 'The email has been updated successfully.', 'quiz-master-next' ), 'success' );
190
- $mlwQuizMasterNext->audit_manager->new_audit( "Email Templates Have Been Saved For Quiz Number $mlw_qmn_email_id" );
191
- }
192
- else
193
- {
194
- $mlwQuizMasterNext->alertManager->newAlert(sprintf(__('There has been an error in this action. Please share this with the developer. Error Code: %s', 'quiz-master-next'), '0017'), 'error');
195
- $mlwQuizMasterNext->log_manager->add("Error 0017", $wpdb->last_error.' from '.$wpdb->last_query, 0, 'error');
196
- }
197
- }
198
-
199
- if (isset($_GET["quiz_id"]))
200
- {
201
- $table_name = $wpdb->prefix . "mlw_quizzes";
202
- $mlw_quiz_options = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE quiz_id=%d LIMIT 1", $_GET["quiz_id"]));
203
- }
204
-
205
- //Load from email array
206
- $from_email_array = maybe_unserialize( $mlw_quiz_options->email_from_text );
207
- if ( ! isset( $from_email_array["from_email"] ) ) {
208
- $from_email_array = array(
209
- 'from_name' => $mlw_quiz_options->email_from_text,
210
- 'from_email' => $mlw_quiz_options->admin_email,
211
- 'reply_to' => 1
212
- );
213
- }
214
-
215
- //Load User Email Templates
216
- if (is_serialized($mlw_quiz_options->user_email_template) && is_array(@unserialize($mlw_quiz_options->user_email_template)))
217
- {
218
- $mlw_qmn_user_email_array = @unserialize($mlw_quiz_options->user_email_template);
219
- }
220
- else
221
- {
222
- $mlw_qmn_user_email_array = array(array(0, 0, $mlw_quiz_options->user_email_template, 'Quiz Results For %QUIZ_NAME%'));
223
- }
224
-
225
- //Load Admin Email Templates
226
- if (is_serialized($mlw_quiz_options->admin_email_template) && is_array(@unserialize($mlw_quiz_options->admin_email_template)))
227
- {
228
- $mlw_qmn_admin_email_array = @unserialize($mlw_quiz_options->admin_email_template);
229
- }
230
- else
231
- {
232
- $mlw_qmn_admin_email_array = array(array(
233
- "begin_score" => 0,
234
- "end_score" => 0,
235
- "message" => $mlw_quiz_options->admin_email_template,
236
- "subject" => 'Quiz Results For %QUIZ_NAME%'
237
- ));
238
- }
239
- wp_enqueue_style( 'qmn_admin_style', plugins_url( '../../css/qsm-admin.css' , __FILE__ ) );
240
  ?>
241
- <script type="text/javascript">
242
- var $j = jQuery.noConflict();
243
- // increase the default animation speed to exaggerate the effect
244
- $j.fx.speeds._default = 1000;
245
- </script>
246
- <script>
247
- /**
248
- * This deletes the user email from the list of emails.
249
- *
250
- * @return id This variable contains the ID of the email so the correct one is deleted.
251
- * @since 4.4.0
252
- */
253
- function delete_email(id)
254
- {
255
- document.getElementById('user_email_'+id).value = "Delete";
256
- document.mlw_quiz_save_email_form.submit();
257
- }
258
 
259
- /**
260
- * This function deletes the admin email from the list of emails.
261
- *
262
- * @return id This variable contains the ID of the email so the right one is deleted.
263
- * @since 4.4.0
264
- */
265
- function delete_admin_email(id)
266
- {
267
- document.getElementById('admin_email_'+id).value = "Delete";
268
- document.mlw_quiz_save_email_form.submit();
269
- }
270
- </script>
271
- <h2><?php esc_html_e( 'Emails', 'quiz-master-next'); ?></h2>
272
- <p>Need assistance with this tab? <a href="https://docs.quizandsurveymaster.com/article/17-sending-emails" target="_blank">Check out the documentation</a> for this tab!</p>
273
- <h3 style="text-align: center;"><?php _e('Template Variables', 'quiz-master-next'); ?></h3>
274
  <div class="template_list_holder">
275
  <div class="template_variable">
276
  <span class="template_name">%CONTACT_X%</span> - <?php _e( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ); ?>
@@ -341,227 +116,72 @@ function qsm_options_emails_tab_content() {
341
  <?php do_action('qmn_template_variable_list'); ?>
342
  </div>
343
  <div style="clear:both;"></div>
344
- <br />
345
- <br />
346
- <form method="post" action="" name="mlw_quiz_add_email_form">
347
- <input type='hidden' name='mlw_add_email_page' value='confirmation' />
348
- <input type='hidden' name='mlw_add_email_quiz_id' value='<?php echo $quiz_id; ?>' />
349
- </form>
350
- <form method="post" action="" name="mlw_quiz_add_admin_email_form">
351
- <input type='hidden' name='mlw_add_admin_email_page' value='confirmation' />
352
- <input type='hidden' name='mlw_add_admin_email_quiz_id' value='<?php echo $quiz_id; ?>' />
353
- </form>
354
- <button id="save_email_button" class="button-primary" onclick="javascript: document.mlw_quiz_save_email_form.submit();"><?php _e('Save Email Templates And Settings', 'quiz-master-next'); ?></button>
355
- <form method="post" action="" name="mlw_quiz_save_email_form">
356
- <table class="form-table">
357
- <tr valign="top">
358
- <th scope="row"><label for="sendUserEmail"><?php _e('Send user email upon completion?', 'quiz-master-next'); ?></label></th>
359
- <td>
360
- <input type="radio" id="radio5" name="sendUserEmail" <?php if ($mlw_quiz_options->send_user_email == 0) {echo 'checked="checked"';} ?> value='0' /><label for="radio5"><?php _e('Yes', 'quiz-master-next'); ?></label><br>
361
- <input type="radio" id="radio6" name="sendUserEmail" <?php if ($mlw_quiz_options->send_user_email == 1) {echo 'checked="checked"';} ?> value='1' /><label for="radio6"><?php _e('No', 'quiz-master-next'); ?></label><br>
362
- </td>
363
- </tr>
364
- <tr valign="top">
365
- <th scope="row"><label for="sendAdminEmail"><?php _e('Send admin email upon completion?', 'quiz-master-next'); ?></label></th>
366
- <td>
367
- <input type="radio" id="radio19" name="sendAdminEmail" <?php if ($mlw_quiz_options->send_admin_email == 0) {echo 'checked="checked"';} ?> value='0' /><label for="radio19"><?php _e('Yes', 'quiz-master-next'); ?></label><br>
368
- <input type="radio" id="radio20" name="sendAdminEmail" <?php if ($mlw_quiz_options->send_admin_email == 1) {echo 'checked="checked"';} ?> value='1' /><label for="radio20"><?php _e('No', 'quiz-master-next'); ?></label><br>
369
- </td>
370
- </tr>
371
- <tr valign="top">
372
- <th scope="row"><label for="adminEmail"><?php _e('What emails should we send the admin email to? Separate emails with a comma.', 'quiz-master-next'); ?></label></th>
373
- <td><input name="adminEmail" type="text" id="adminEmail" value="<?php echo $mlw_quiz_options->admin_email; ?>" class="regular-text" /></td>
374
- </tr>
375
- <tr valign="top">
376
- <th scope="row"><label for="emailFromText"><?php _e("What is the From Name for the email sent to users and admin?", 'quiz-master-next'); ?></label></th>
377
- <td><input name="emailFromText" type="text" id="emailFromText" value="<?php echo $from_email_array["from_name"]; ?>" class="regular-text" /></td>
378
- </tr>
379
- <tr valign="top">
380
- <th scope="row"><label for="emailFromAddress"><?php _e("What is the From Email address for the email sent to users and admin?", 'quiz-master-next'); ?></label></th>
381
- <td><input name="emailFromAddress" type="text" id="emailFromAddress" value="<?php echo $from_email_array["from_email"]; ?>" class="regular-text" /></td>
382
- </tr>
383
- <tr valign="top">
384
- <th scope="row"><label for="replyToUser"><?php _e('Add user\'s email as Reply-To on admin email?', 'quiz-master-next'); ?></label></th>
385
- <td>
386
- <input type="radio" id="radio19" name="replyToUser" <?php checked( $from_email_array["reply_to"], 0 ); ?> value='0' /><label for="radio19"><?php _e('Yes', 'quiz-master-next'); ?></label><br>
387
- <input type="radio" id="radio20" name="replyToUser" <?php checked( $from_email_array["reply_to"], 1 ); ?> value='1' /><label for="radio20"><?php _e('No', 'quiz-master-next'); ?></label><br>
388
- </td>
389
- </tr>
390
- </table>
391
- <br />
392
- <br />
393
- <h3><?php _e('Email Sent To User', 'quiz-master-next'); ?></h3>
394
- <a id="new_email_button_top" class="button" href="#" onclick="javascript: document.mlw_quiz_add_email_form.submit();"><?php _e('Add New User Email', 'quiz-master-next'); ?></a>
395
- <table class="widefat">
396
- <thead>
397
- <tr>
398
- <th>ID</th>
399
- <th><?php _e('Score Greater Than Or Equal To', 'quiz-master-next'); ?></th>
400
- <th><?php _e('Score Less Than Or Equal To', 'quiz-master-next'); ?></th>
401
- <th><?php _e('Subject', 'quiz-master-next'); ?></th>
402
- <th><?php _e('Email To Send', 'quiz-master-next'); ?></th>
403
- </tr>
404
- </thead>
405
- <tbody>
406
- <?php
407
- $mlw_each_count = 0;
408
- $alternate = "";
409
- foreach($mlw_qmn_user_email_array as $mlw_each)
410
- {
411
- if($alternate) $alternate = "";
412
- else $alternate = " class=\"alternate\"";
413
- $mlw_each_count += 1;
414
- if (!isset($mlw_each[3]))
415
- {
416
- $mlw_each[3] = "Quiz Results For %QUIZ_NAME%";
417
- }
418
- if ($mlw_each[0] == 0 && $mlw_each[1] == 0)
419
- {
420
- echo "<tr{$alternate}>";
421
- echo "<td>";
422
- echo "Default";
423
- echo "</td>";
424
- echo "<td>";
425
- echo "<input type='hidden' id='user_email_begin_".$mlw_each_count."' name='user_email_begin_".$mlw_each_count."' value='0'/>-";
426
- echo "</td>";
427
- echo "<td>";
428
- echo "<input type='hidden' id='user_email_end_".$mlw_each_count."' name='user_email_end_".$mlw_each_count."' value='0'/>-";
429
- echo "</td>";
430
- echo "<td>";
431
- echo "<input type='text' id='user_email_subject_".$mlw_each_count."' name='user_email_subject_".$mlw_each_count."' value='".$mlw_each[3]."' />";
432
- echo "</td>";
433
- echo "<td>";
434
- echo "<textarea cols='80' rows='15' id='user_email_".$mlw_each_count."' name='user_email_".$mlw_each_count."'>".$mlw_each[2]."</textarea>";
435
- echo "</td>";
436
- echo "</tr>";
437
- break;
438
- }
439
- else
440
- {
441
- echo "<tr{$alternate}>";
442
- echo "<td>";
443
- echo $mlw_each_count."<div><span style='color:green;font-size:12px;'><a onclick=\"\$j('#trying_delete_email_".$mlw_each_count."').show();\">Delete</a></span></div><div style=\"display: none;\" id='trying_delete_email_".$mlw_each_count."'>Are you sure?<br /><a onclick=\"delete_email(".$mlw_each_count.")\">Yes</a>|<a onclick=\"\$j('#trying_delete_email_".$mlw_each_count."').hide();\">No</a></div>";
444
- echo "</td>";
445
- echo "<td>";
446
- echo "<input type='text' id='user_email_begin_".$mlw_each_count."' name='user_email_begin_".$mlw_each_count."' title='What score must the user score better than to see this page' value='".$mlw_each[0]."'/>";
447
- echo "</td>";
448
- echo "<td>";
449
- echo "<input type='text' id='user_email_end_".$mlw_each_count."' name='user_email_end_".$mlw_each_count."' title='What score must the user score worse than to see this page' value='".$mlw_each[1]."' />";
450
- echo "</td>";
451
- echo "<td>";
452
- echo "<input type='text' id='user_email_subject_".$mlw_each_count."' name='user_email_subject_".$mlw_each_count."' value='".$mlw_each[3]."' />";
453
- echo "</td>";
454
- echo "<td>";
455
- echo "<textarea cols='80' rows='15' id='user_email_".$mlw_each_count."' title='What email will the user be sent' name='user_email_".$mlw_each_count."'>".$mlw_each[2]."</textarea>";
456
- echo "</td>";
457
- echo "</tr>";
458
- }
459
- }
460
- ?>
461
- </tbody>
462
- <tfoot>
463
- <tr>
464
- <th>ID</th>
465
- <th><?php _e('Score Greater Than Or Equal To', 'quiz-master-next'); ?></th>
466
- <th><?php _e('Score Less Than Or Equal To', 'quiz-master-next'); ?></th>
467
- <th><?php _e('Subject', 'quiz-master-next'); ?></th>
468
- <th><?php _e('Email To Send', 'quiz-master-next'); ?></th>
469
- </tr>
470
- </tfoot>
471
- </table>
472
- <a id="new_email_button_bottom" class="button" href="#" onclick="javascript: document.mlw_quiz_add_email_form.submit();"><?php _e('Add New User Email', 'quiz-master-next'); ?></a>
473
- <input type='hidden' name='mlw_save_email_template' value='confirmation' />
474
- <input type='hidden' name='mlw_email_quiz_id' value='<?php echo $quiz_id; ?>' />
475
- <input type='hidden' name='mlw_email_template_total' value='<?php echo $mlw_each_count; ?>' />
476
- <br />
477
- <br />
478
- <br />
479
- <br />
480
- <h3><?php _e('Email Sent To Admin', 'quiz-master-next'); ?></h3>
481
- <a id="new_admin_email_button_top" class="button" href="#" onclick="javascript: document.mlw_quiz_add_admin_email_form.submit();"><?php _e('Add New Admin Email', 'quiz-master-next'); ?></a>
482
- <table class="widefat">
483
- <thead>
484
- <tr>
485
- <th>ID</th>
486
- <th><?php _e('Score Greater Than Or Equal To', 'quiz-master-next'); ?></th>
487
- <th><?php _e('Score Less Than Or Equal To', 'quiz-master-next'); ?></th>
488
- <th><?php _e('Subject', 'quiz-master-next'); ?></th>
489
- <th><?php _e('Email To Send', 'quiz-master-next'); ?></th>
490
- </tr>
491
- </thead>
492
- <tbody>
493
- <?php
494
- $mlw_admin_count = 0;
495
- $alternate = "";
496
- foreach($mlw_qmn_admin_email_array as $mlw_each)
497
- {
498
- if($alternate) $alternate = "";
499
- else $alternate = " class=\"alternate\"";
500
- $mlw_admin_count += 1;
501
- if (!isset($mlw_each["subject"]))
502
- {
503
- $mlw_each[3] = "Quiz Results For %QUIZ_NAME%";
504
- }
505
- if ($mlw_each["begin_score"] == 0 && $mlw_each["end_score"] == 0)
506
- {
507
- echo "<tr{$alternate}>";
508
- echo "<td>";
509
- echo "Default";
510
- echo "</td>";
511
- echo "<td>";
512
- echo "<input type='hidden' id='admin_email_begin_".$mlw_admin_count."' name='admin_email_begin_".$mlw_admin_count."' value='0'/>-";
513
- echo "</td>";
514
- echo "<td>";
515
- echo "<input type='hidden' id='admin_email_end_".$mlw_admin_count."' name='admin_email_end_".$mlw_admin_count."' value='0'/>-";
516
- echo "</td>";
517
- echo "<td>";
518
- echo "<input type='text' id='admin_email_subject_".$mlw_admin_count."' name='admin_email_subject_".$mlw_admin_count."' value='".$mlw_each["subject"]."' />";
519
- echo "</td>";
520
- echo "<td>";
521
- echo "<textarea cols='80' rows='15' id='admin_email_".$mlw_admin_count."' name='admin_email_".$mlw_admin_count."'>".$mlw_each["message"]."</textarea>";
522
- echo "</td>";
523
- echo "</tr>";
524
- break;
525
- }
526
- else
527
- {
528
- echo "<tr{$alternate}>";
529
- echo "<td>";
530
- echo $mlw_admin_count."<div><span style='color:green;font-size:12px;'><a onclick=\"\$j('#trying_delete_admin_email_".$mlw_admin_count."').show();\">Delete</a></span></div><div style=\"display: none;\" id='trying_delete_admin_email_".$mlw_admin_count."'>Are you sure?<br /><a onclick=\"delete_admin_email(".$mlw_admin_count.")\">Yes</a>|<a onclick=\"\$j('#trying_delete_admin_email_".$mlw_admin_count."').hide();\">No</a></div>";
531
- echo "</td>";
532
- echo "<td>";
533
- echo "<input type='text' id='admin_email_begin_".$mlw_admin_count."' name='admin_email_begin_".$mlw_admin_count."' title='What score must the user score better than to see this page' value='".$mlw_each["begin_score"]."'/>";
534
- echo "</td>";
535
- echo "<td>";
536
- echo "<input type='text' id='admin_email_end_".$mlw_admin_count."' name='admin_email_end_".$mlw_admin_count."' title='What score must the user score worse than to see this page' value='".$mlw_each["end_score"]."' />";
537
- echo "</td>";
538
- echo "<td>";
539
- echo "<input type='text' id='admin_email_subject_".$mlw_admin_count."' name='admin_email_subject_".$mlw_admin_count."' value='".$mlw_each["subject"]."' />";
540
- echo "</td>";
541
- echo "<td>";
542
- echo "<textarea cols='80' rows='15' id='admin_email_".$mlw_admin_count."' title='What email will the user be sent' name='admin_email_".$mlw_admin_count."'>".$mlw_each["message"]."</textarea>";
543
- echo "</td>";
544
- echo "</tr>";
545
- }
546
- }
547
- ?>
548
- </tbody>
549
- <tfoot>
550
- <tr>
551
- <th>ID</th>
552
- <th><?php _e('Score Greater Than Or Equal To', 'quiz-master-next'); ?></th>
553
- <th><?php _e('Score Less Than Or Equal To', 'quiz-master-next'); ?></th>
554
- <th><?php _e('Subject', 'quiz-master-next'); ?></th>
555
- <th><?php _e('Email To Send', 'quiz-master-next'); ?></th>
556
- </tr>
557
- </tfoot>
558
- </table>
559
- <a id="new_admin_email_button_bottom" class="button" href="#" onclick="javascript: document.mlw_quiz_add_admin_email_form.submit();"><?php _e('Add New Admin Email', 'quiz-master-next'); ?></a>
560
- <input type='hidden' name='mlw_email_admin_total' value='<?php echo $mlw_admin_count; ?>' />
561
- </form>
562
- <br />
563
- <br />
564
- <button id="save_email_button" class="button-primary" onclick="javascript: document.mlw_quiz_save_email_form.submit();"><?php _e('Save Email Templates And Settings', 'quiz-master-next'); ?></button>
565
  <?php
566
  }
567
  ?>
1
  <?php
2
+ /**
3
+ * Creates the emails page tab when editing quizzes.
4
+ *
5
+ * @package QSM
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
 
12
  /**
13
  * Creates the email tab in the Quiz Settings Page
14
  *
15
  * @return void
16
+ * @since 6.1.0
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
 
24
  /**
25
  * Creates the email content that is displayed on the email tab.
30
  function qsm_options_emails_tab_content() {
31
  global $wpdb;
32
  global $mlwQuizMasterNext;
33
+ $quiz_id = intval( $_GET['quiz_id'] );
34
+ $js_data = array(
35
+ 'quizID' => $quiz_id,
36
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
37
+ );
38
+ wp_enqueue_script( 'qsm_emails_admin_script', plugins_url( '../../js/qsm-admin-emails.js', __FILE__ ), array( 'jquery-ui-sortable', 'qmn_admin_js' ), $mlwQuizMasterNext->version );
39
+ wp_localize_script( 'qsm_emails_admin_script', 'qsmEmailsObject', $js_data );
40
+ wp_enqueue_editor();
41
+ wp_enqueue_media();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ?>
43
+ <h2><?php esc_html_e( 'Emails', 'quiz-master-next' ); ?></h2>
44
+ <p>Need assistance with this tab? <a href="https://docs.quizandsurveymaster.com/article/17-sending-emails" target="_blank">Check out the documentation</a> for this tab!</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ <!-- Template Variable Section -->
47
+ <section>
48
+ <h3 style="text-align: center;"><?php esc_html_e( 'Template Variables', 'quiz-master-next' ); ?></h3>
 
 
 
 
 
 
 
 
 
 
 
 
49
  <div class="template_list_holder">
50
  <div class="template_variable">
51
  <span class="template_name">%CONTACT_X%</span> - <?php _e( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ); ?>
116
  <?php do_action('qmn_template_variable_list'); ?>
117
  </div>
118
  <div style="clear:both;"></div>
119
+ </section>
120
+
121
+ <!-- Emails Section -->
122
+ <section>
123
+ <h3>Your Emails</h3>
124
+ <button class="save-emails button-primary"><?php esc_html_e( 'Save Emails', 'quiz-master-next' ); ?></button>
125
+ <button class="add-new-email button"><?php esc_html_e( 'Add New Email', 'quiz-master-next' ); ?></button>
126
+ <div id="emails"></div>
127
+ <button class="save-emails button-primary"><?php esc_html_e( 'Save Emails', 'quiz-master-next' ); ?></button>
128
+ <button class="add-new-email button"><?php esc_html_e( 'Add New Email', 'quiz-master-next' ); ?></button>
129
+ </section>
130
+
131
+ <!-- Templates -->
132
+ <script type="text/template" id="tmpl-email">
133
+ <div class="email">
134
+ <header class="email-header">
135
+ <div><button class="delete-email-button"><span class="dashicons dashicons-trash"></span></button></div>
136
+ </header>
137
+ <main class="email-content">
138
+ <div class="email-when">
139
+ <div class="email-content-header">
140
+ <h4>When...</h4>
141
+ <p>Set conditions for when this email should be sent. Leave empty to set this as an email that is always sent.</p>
142
+ </div>
143
+ <div class="email-when-conditions">
144
+ <!-- Conditions go here. Review template below. -->
145
+ </div>
146
+ <button class="new-condition button"><?php esc_html_e( 'Add additional condition', 'quiz-master-next' ); ?></button>
147
+ </div>
148
+ <div class="email-show">
149
+ <div class="email-content-header">
150
+ <h4>...Send</h4>
151
+ <p>Create the email that should be sent when the conditions are met.</p>
152
+ </div>
153
+ <label>Who to send the email to? Put %USER_EMAIL% to send to user</label>
154
+ <input type="email" class="to-email" value="{{ data.to }}">
155
+ <label>Email Subject</label>
156
+ <input type="text" class="subject" value="{{ data.subject }}">
157
+ <label>Email Content</label>
158
+ <textarea id="email-template-{{ data.id }}" class="email-template">{{{ data.content }}}</textarea>
159
+ <label><input type="checkbox" class="reply-to" <# if ( "true" == data.replyTo || true == data.replyTo ) { #>checked<# } #>>Add user email as Reply-To</label>
160
+ </div>
161
+ </main>
162
+ </div>
163
+ </script>
164
+
165
+ <script type="text/template" id="tmpl-email-condition">
166
+ <div class="email-condition">
167
+ <button class="delete-condition-button"><span class="dashicons dashicons-trash"></span></button>
168
+ <select class="email-condition-criteria">
169
+ <option value="points" <# if (data.criteria == 'points') { #>selected<# } #>>Total points earned</option>
170
+ <option value="score" <# if (data.criteria == 'score') { #>selected<# } #>>Correct score percentage</option>
171
+ <?php do_action( 'qsm_email_condition_criteria' ); ?>
172
+ </select>
173
+ <select class="email-condition-operator">
174
+ <option value="equal" <# if (data.operator == 'equal') { #>selected<# } #>>is equal to</option>
175
+ <option value="not-equal" <# if (data.operator == 'not-equal') { #>selected<# } #>>is not equal to</option>
176
+ <option value="greater-equal" <# if (data.operator == 'greater-equal') { #>selected<# } #>>is greater than or equal to</option>
177
+ <option value="greater" <# if (data.operator == 'greater') { #>selected<# } #>>is greater than</option>
178
+ <option value="less-equal" <# if (data.operator == 'less-equal') { #>selected<# } #>>is less than or equal to</option>
179
+ <option value="less" <# if (data.operator == 'less') { #>selected<# } #>>is less than</option>
180
+ <?php do_action( 'qsm_email_condition_operator' ); ?>
181
+ </select>
182
+ <input type="text" class="email-condition-value" value="{{ data.value }}">
183
+ </div>
184
+ </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  <?php
186
  }
187
  ?>
php/admin/options-page-option-tab.php CHANGED
@@ -1,26 +1,27 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
3
 
4
  /**
5
- * Adds the Options tab to the Quiz Settings page.
6
- *
7
- * @return void
8
- * @since 4.4.0
9
- */
10
- function qmn_settings_options_tab() {
11
  global $mlwQuizMasterNext;
12
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( "Options", 'quiz-master-next' ), 'mlw_options_option_tab_content' );
13
  }
14
- add_action( "plugins_loaded", 'qmn_settings_options_tab', 5 );
15
 
16
  /**
17
- * Adds the options content to the Quiz Settings page.
18
- *
19
- * @return void
20
- * @since 4.4.0
21
- */
22
- function mlw_options_option_tab_content() {
23
-
24
  global $wpdb;
25
  global $mlwQuizMasterNext;
26
  $mlwQuizMasterNext->pluginHelper->generate_settings_section( 'quiz_options' );
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
 
6
  /**
7
+ * Adds the Options tab to the Quiz Settings page.
8
+ *
9
+ * @return void
10
+ * @since 6.2.0
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
 
18
  /**
19
+ * Adds the options content to the Quiz Settings page.
20
+ *
21
+ * @return void
22
+ * @since 6.2.0
23
+ */
24
+ function qsm_options_option_tab_content() {
 
25
  global $wpdb;
26
  global $mlwQuizMasterNext;
27
  $mlwQuizMasterNext->pluginHelper->generate_settings_section( 'quiz_options' );
php/admin/options-page-preview-tab.php CHANGED
@@ -1,34 +1,36 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
 
 
3
 
4
  /**
5
- * Adds the Settings Preview tab to the Quiz Settings page.
6
- *
7
- * @return void
8
- * @since 4.4.0
9
- */
10
- function qmn_settings_preview_tab()
11
- {
12
  global $mlwQuizMasterNext;
13
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs(__("Preview", 'quiz-master-next'), 'mlw_options_preview_tab_content');
14
  }
15
- add_action("plugins_loaded", 'qmn_settings_preview_tab', 5);
16
 
17
  /**
18
- * Adds the options preview content to the Options preview tab.
19
- *
20
- * @return void
21
- * @since 4.4.0
22
- */
23
- function mlw_options_preview_tab_content()
24
- {
 
 
25
  ?>
26
- <div id="tabs-preview" class="mlw_tab_content">
27
- <p>If your quiz looks different on the front end compared to this preview, then there is a conflict with your theme. Check out our <a href="https://docs.quizandsurveymaster.com/article/21-common-theme-conflict-fixes" target="_blank">Common Theme Conflict Fixes</a>.</a></p>
28
- <?php
29
- echo do_shortcode( '[mlw_quizmaster quiz='.intval($_GET["quiz_id"]).']' );
30
- ?>
31
- </div>
32
  <?php
33
  }
34
  ?>
1
  <?php
2
+ /**
3
+ * Creates the "Preview" tab when editing the quiz.
4
+ *
5
+ * @package QSM
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
 
12
  /**
13
+ * Adds the Settings Preview tab to the Quiz Settings page.
14
+ *
15
+ * @since 6.2.0
16
+ */
17
+ function qsm_settings_preview_tab() {
 
 
18
  global $mlwQuizMasterNext;
19
+ $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Preview', 'quiz-master-next' ), 'qsm_options_preview_tab_content' );
20
  }
21
+ add_action( 'plugins_loaded', 'qsm_settings_preview_tab', 5 );
22
 
23
  /**
24
+ * Adds the options preview content to the Options preview tab.
25
+ *
26
+ * @since 6.2.0
27
+ */
28
+ function qsm_options_preview_tab_content() {
29
+ ?>
30
+ <p>If your quiz looks different on the front end compared to this preview, then there is a conflict with your theme. Check out our <a href="https://docs.quizandsurveymaster.com/article/21-common-theme-conflict-fixes" target="_blank">Common Theme Conflict Fixes</a>.</p>
31
+ <?php
32
+ echo do_shortcode( '[qsm quiz=' . intval( $_GET['quiz_id'] ) . ']' );
33
  ?>
 
 
 
 
 
 
34
  <?php
35
  }
36
  ?>
php/admin/options-page-questions-tab.php CHANGED
@@ -42,7 +42,7 @@ function qsm_options_questions_tab_content() {
42
 
43
  // Scripts and styles.
44
  wp_enqueue_script( 'micromodal_script', plugins_url( '../../js/micromodal.min.js', __FILE__ ) );
45
- wp_enqueue_script( 'qsm_admin_question_js', plugins_url( '../../js/qsm-admin-question.js', __FILE__ ), array( 'backbone', 'underscore', 'jquery-ui-sortable', 'wp-util', 'micromodal_script' ), $mlwQuizMasterNext->version, true );
46
  wp_localize_script( 'qsm_admin_question_js', 'qsmQuestionSettings', $json_data );
47
  wp_enqueue_style( 'qsm_admin_question_css', plugins_url( '../../css/qsm-admin-question.css', __FILE__ ), array(), $mlwQuizMasterNext->version );
48
  wp_enqueue_script( 'math_jax', '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' );
@@ -80,7 +80,6 @@ function qsm_options_questions_tab_content() {
80
  ?>
81
  <h3>Questions</h3>
82
  <p>Use this tab to create and modify the different pages of your quiz or survey as well as the questions on each page. Click "Create New Page" to get started! Need more information? Check out the <a href="https://docs.quizandsurveymaster.com/article/19-creating-pages-and-questions" target="_blank">documentation for this tab!</a></p>
83
- <div class="questions-messages"></div>
84
  <div class="question-controls">
85
  <div>
86
  <button class="new-page-button button">Create New Page</button>
@@ -187,13 +186,6 @@ function qsm_options_questions_tab_content() {
187
 
188
  <!--Views-->
189
 
190
- <!-- View for Notices -->
191
- <script type="text/template" id="tmpl-notice">
192
- <div class="notice notice-{{data.type}}">
193
- <p>{{data.message}}</p>
194
- </div>
195
- </script>
196
-
197
  <!-- View for Page -->
198
  <script type="text/template" id="tmpl-page">
199
  <div class="page page-new">
42
 
43
  // Scripts and styles.
44
  wp_enqueue_script( 'micromodal_script', plugins_url( '../../js/micromodal.min.js', __FILE__ ) );
45
+ wp_enqueue_script( 'qsm_admin_question_js', plugins_url( '../../js/qsm-admin-question.js', __FILE__ ), array( 'backbone', 'underscore', 'jquery-ui-sortable', 'wp-util', 'micromodal_script', 'qmn_admin_js' ), $mlwQuizMasterNext->version, true );
46
  wp_localize_script( 'qsm_admin_question_js', 'qsmQuestionSettings', $json_data );
47
  wp_enqueue_style( 'qsm_admin_question_css', plugins_url( '../../css/qsm-admin-question.css', __FILE__ ), array(), $mlwQuizMasterNext->version );
48
  wp_enqueue_script( 'math_jax', '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' );
80
  ?>
81
  <h3>Questions</h3>
82
  <p>Use this tab to create and modify the different pages of your quiz or survey as well as the questions on each page. Click "Create New Page" to get started! Need more information? Check out the <a href="https://docs.quizandsurveymaster.com/article/19-creating-pages-and-questions" target="_blank">documentation for this tab!</a></p>
 
83
  <div class="question-controls">
84
  <div>
85
  <button class="new-page-button button">Create New Page</button>
186
 
187
  <!--Views-->
188
 
 
 
 
 
 
 
 
189
  <!-- View for Page -->
190
  <script type="text/template" id="tmpl-page">
191
  <div class="page page-new">
php/admin/options-page-results-page-tab.php CHANGED
@@ -1,131 +1,49 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
 
 
3
 
4
  /**
5
- * Adds the Results tab to the Quiz Settings page.
6
- *
7
- * @return void
8
- * @since 4.4.0
9
- */
10
- function qmn_settings_results_tab()
11
- {
12
  global $mlwQuizMasterNext;
13
- $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs(__("Results Pages", 'quiz-master-next'), 'mlw_options_results_tab_content');
14
  }
15
- add_action("plugins_loaded", 'qmn_settings_results_tab', 5);
16
 
17
  /**
18
- * Adds the Results page content to the Results tab.
19
- *
20
- * @return void
21
- * @since 4.4.0
22
- */
23
- function mlw_options_results_tab_content()
24
- {
25
  global $wpdb;
26
  global $mlwQuizMasterNext;
27
- $quiz_id = $_GET["quiz_id"];
28
- //Check to add new results page
29
- if (isset($_POST["mlw_add_landing_page"]) && $_POST["mlw_add_landing_page"] == "confirmation")
30
- {
31
- //Function variables
32
- $mlw_qmn_landing_id = intval($_POST["mlw_add_landing_quiz_id"]);
33
- $mlw_qmn_message_after = $wpdb->get_var( $wpdb->prepare( "SELECT message_after FROM ".$wpdb->prefix."mlw_quizzes WHERE quiz_id=%d", $mlw_qmn_landing_id ) );
34
- //Load message_after and check if it is array already. If not, turn it into one
35
- if (is_serialized($mlw_qmn_message_after) && is_array(@unserialize($mlw_qmn_message_after)))
36
- {
37
- $mlw_qmn_landing_array = @unserialize($mlw_qmn_message_after);
38
- $mlw_new_landing_array = array(0, 100, 'Enter Your Text Here', "redirect_url" => '');
39
- array_unshift($mlw_qmn_landing_array , $mlw_new_landing_array);
40
- $mlw_qmn_landing_array = serialize($mlw_qmn_landing_array);
41
-
42
- }
43
- else
44
- {
45
- $mlw_qmn_landing_array = array(array(0, 0, $mlw_qmn_message_after));
46
- $mlw_new_landing_array = array(0, 100, 'Enter Your Text Here', "redirect_url" => '');
47
- array_unshift($mlw_qmn_landing_array , $mlw_new_landing_array);
48
- $mlw_qmn_landing_array = serialize($mlw_qmn_landing_array);
49
- }
50
-
51
- //Update message_after with new array then check to see if worked
52
- $mlw_new_landing_results = $wpdb->query( $wpdb->prepare( "UPDATE ".$wpdb->prefix."mlw_quizzes SET message_after=%s, last_activity='".date("Y-m-d H:i:s")."' WHERE quiz_id=%d", $mlw_qmn_landing_array, $mlw_qmn_landing_id ) );
53
- if ( false != $mlw_new_landing_results ) {
54
- $mlwQuizMasterNext->alertManager->newAlert(__('The results page has been added successfully.', 'quiz-master-next'), 'success');
55
- $mlwQuizMasterNext->audit_manager->new_audit( "New Results Page Has Been Created For Quiz Number $mlw_qmn_landing_id" );
56
- } else {
57
- $mlwQuizMasterNext->alertManager->newAlert(sprintf(__('There has been an error in this action. Please share this with the developer. Error Code: %s', 'quiz-master-next'), '0013'), 'error');
58
- $mlwQuizMasterNext->log_manager->add("Error 0013", $wpdb->last_error.' from '.$wpdb->last_query, 0, 'error');
59
- }
60
- }
61
-
62
- //Check to save landing pages
63
- if (isset($_POST["mlw_save_landing_pages"]) && $_POST["mlw_save_landing_pages"] == "confirmation")
64
- {
65
- //Function Variables
66
- $mlw_qmn_landing_id = intval($_POST["mlw_landing_quiz_id"]);
67
- $mlw_qmn_landing_total = intval($_POST["mlw_landing_page_total"]);
68
-
69
- //Create new array
70
- $i = 1;
71
- $mlw_qmn_new_landing_array = array();
72
- while ($i <= $mlw_qmn_landing_total)
73
- {
74
- if ($_POST["message_after_".$i] != "Delete")
75
- {
76
- $mlw_qmn_landing_each = array(intval($_POST["message_after_begin_".$i]), intval($_POST["message_after_end_".$i]), htmlspecialchars(stripslashes($_POST["message_after_".$i]), ENT_QUOTES), "redirect_url" => esc_url_raw($_POST["redirect_".$i]));
77
- $mlw_qmn_new_landing_array[] = $mlw_qmn_landing_each;
78
- }
79
- $i++;
80
- }
81
- $mlw_qmn_new_landing_array = serialize($mlw_qmn_new_landing_array);
82
- $mlw_new_landing_results = $wpdb->query( $wpdb->prepare( "UPDATE ".$wpdb->prefix."mlw_quizzes SET message_after='%s', last_activity='".date("Y-m-d H:i:s")."' WHERE quiz_id=%d", $mlw_qmn_new_landing_array, $mlw_qmn_landing_id ) );
83
- if ( false != $mlw_new_landing_results ) {
84
- $mlwQuizMasterNext->alertManager->newAlert(__('The results page has been saved successfully.', 'quiz-master-next'), 'success');
85
- $mlwQuizMasterNext->audit_manager->new_audit( "Results Pages Have Been Saved For Quiz Number $mlw_qmn_landing_id" );
86
- } else {
87
- $mlwQuizMasterNext->alertManager->newAlert(sprintf(__('There has been an error in this action. Please share this with the developer. Error Code: %s', 'quiz-master-next'), '0014'), 'error');
88
- $mlwQuizMasterNext->log_manager->add("Error 0014", $wpdb->last_error.' from '.$wpdb->last_query, 0, 'error');
89
- }
90
- }
91
-
92
- if (isset($_GET["quiz_id"]))
93
- {
94
- $table_name = $wpdb->prefix . "mlw_quizzes";
95
- $mlw_quiz_options = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE quiz_id=%d LIMIT 1", $_GET["quiz_id"]));
96
- }
97
-
98
- //Load Landing Pages
99
- if (is_serialized($mlw_quiz_options->message_after) && is_array(@unserialize($mlw_quiz_options->message_after)))
100
- {
101
- $mlw_message_after_array = @unserialize($mlw_quiz_options->message_after);
102
- }
103
- else
104
- {
105
- $mlw_message_after_array = array(array(0, 0, $mlw_quiz_options->message_after, "redirect_url" => ''));
106
- }
107
- wp_enqueue_style( 'qmn_admin_style', plugins_url( '../../css/qsm-admin.css' , __FILE__ ) );
108
  ?>
109
- <div id="tabs-6" class="mlw_tab_content">
110
- <script>
111
- var $j = jQuery.noConflict();
112
- // increase the default animation speed to exaggerate the effect
113
- $j.fx.speeds._default = 1000;
114
- function delete_landing(id)
115
- {
116
- var qmn_results_editor = tinyMCE.get('message_after_'+id);
117
- if (qmn_results_editor)
118
- {
119
- tinyMCE.get('message_after_'+id).setContent('Delete');
120
- }
121
- else
122
- {
123
- document.getElementById('message_after_'+id).value = "Delete";
124
- }
125
- document.mlw_quiz_save_landing_form.submit();
126
- }
127
- </script>
128
- <h3 style="text-align: center;"><?php _e("Template Variables", 'quiz-master-next'); ?></h3>
129
  <div class="template_list_holder">
130
  <div class="template_variable">
131
  <span class="template_name">%CONTACT_X%</span> - <?php _e( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ); ?>
@@ -199,95 +117,68 @@ function mlw_options_results_tab_content()
199
  <?php do_action('qmn_template_variable_list'); ?>
200
  </div>
201
  <div style="clear:both;"></div>
202
- <button id="save_landing_button" class="button-primary" onclick="javascript: document.mlw_quiz_save_landing_form.submit();"><?php _e('Save Results Pages', 'quiz-master-next'); ?></button>
203
- <button id="new_landing_button" class="button" onclick="javascript: document.mlw_quiz_add_landing_form.submit();"><?php _e('Add New Results Page', 'quiz-master-next'); ?></button>
204
- <form method="post" action="" name="mlw_quiz_save_landing_form" style=" display:inline!important;">
205
- <table class="widefat">
206
- <thead>
207
- <tr>
208
- <th>ID</th>
209
- <th><?php _e('Score Greater Than Or Equal To', 'quiz-master-next'); ?></th>
210
- <th><?php _e('Score Less Than Or Equal To', 'quiz-master-next'); ?></th>
211
- <th><?php _e('Results Page Shown', 'quiz-master-next'); ?></th>
212
- <th><?php _e('Redirect URL (Beta)', 'quiz-master-next'); ?></th>
213
- </tr>
214
- </thead>
215
- <tbody>
216
- <?php
217
- $mlw_each_count = 0;
218
- $alternate = "";
219
- foreach($mlw_message_after_array as $mlw_each)
220
- {
221
- if($alternate) $alternate = "";
222
- else $alternate = " class=\"alternate\"";
223
- $mlw_each_count += 1;
224
- if ($mlw_each[0] == 0 && $mlw_each[1] == 0)
225
- {
226
- echo "<tr{$alternate}>";
227
- echo "<td>";
228
- echo "Default";
229
- echo "</td>";
230
- echo "<td>";
231
- echo "<input type='hidden' id='message_after_begin_".$mlw_each_count."' name='message_after_begin_".$mlw_each_count."' value='0'/>-";
232
- echo "</td>";
233
- echo "<td>";
234
- echo "<input type='hidden' id='message_after_end_".$mlw_each_count."' name='message_after_end_".$mlw_each_count."' value='0'/>-";
235
- echo "</td>";
236
- echo "<td>";
237
- wp_editor( htmlspecialchars_decode($mlw_each[2], ENT_QUOTES), "message_after_".$mlw_each_count );
238
- //echo "<textarea cols='80' rows='15' id='message_after_".$mlw_each_count."' name='message_after_".$mlw_each_count."'>".$mlw_each[2]."</textarea>";
239
- echo "</td>";
240
- echo "<td>";
241
- echo "<input type='text' id='redirect_".$mlw_each_count."' name='redirect_".$mlw_each_count."' value='".esc_url($mlw_each["redirect_url"])."'/>";
242
- echo "</td>";
243
- echo "</tr>";
244
- break;
245
- }
246
- else
247
- {
248
- echo "<tr{$alternate}>";
249
- echo "<td>";
250
- echo $mlw_each_count."<div><span style='color:green;font-size:12px;'><a onclick=\"\$j('#trying_delete_".$mlw_each_count."').show();\">".__('Delete', 'quiz-master-next')."</a></span></div><div style=\"display: none;\" id='trying_delete_".$mlw_each_count."'>".__('Are you sure?', 'quiz-master-next')."<br /><a onclick=\"delete_landing(".$mlw_each_count.")\">".__('Yes', 'quiz-master-next')."</a>|<a onclick=\"\$j('#trying_delete_".$mlw_each_count."').hide();\">".__('No', 'quiz-master-next')."</a></div>";
251
- echo "</td>";
252
- echo "<td>";
253
- echo "<input type='text' id='message_after_begin_".$mlw_each_count."' name='message_after_begin_".$mlw_each_count."' title='What score must the user score better than to see this page' value='".$mlw_each[0]."'/>";
254
- echo "</td>";
255
- echo "<td>";
256
- echo "<input type='text' id='message_after_end_".$mlw_each_count."' name='message_after_end_".$mlw_each_count."' title='What score must the user score worse than to see this page' value='".$mlw_each[1]."' />";
257
- echo "</td>";
258
- echo "<td>";
259
- wp_editor( htmlspecialchars_decode($mlw_each[2], ENT_QUOTES), "message_after_".$mlw_each_count );
260
- //echo "<textarea cols='80' rows='15' id='message_after_".$mlw_each_count."' title='What text will the user see when reaching this page' name='message_after_".$mlw_each_count."'>".$mlw_each[2]."</textarea>";
261
- echo "</td>";
262
- echo "<td>";
263
- echo "<input type='text' id='redirect_".$mlw_each_count."' name='redirect_".$mlw_each_count."' value='".esc_url($mlw_each["redirect_url"])."'/>";
264
- echo "</td>";
265
- echo "</tr>";
266
- }
267
- }
268
- ?>
269
- </tbody>
270
- <tfoot>
271
- <tr>
272
- <th>ID</th>
273
- <th><?php _e('Score Greater Than Or Equal To', 'quiz-master-next'); ?></th>
274
- <th><?php _e('Score Less Than Or Equal To', 'quiz-master-next'); ?></th>
275
- <th><?php _e('Results Page Shown', 'quiz-master-next'); ?></th>
276
- <th><?php _e('Redirect URL (Beta)', 'quiz-master-next'); ?></th>
277
- </tr>
278
- </tfoot>
279
- </table>
280
- <input type='hidden' name='mlw_save_landing_pages' value='confirmation' />
281
- <input type='hidden' name='mlw_landing_quiz_id' value='<?php echo $quiz_id; ?>' />
282
- <input type='hidden' name='mlw_landing_page_total' value='<?php echo $mlw_each_count; ?>' />
283
- <button id="save_landing_button" class="button-primary" onclick="javascript: document.mlw_quiz_save_landing_form.submit();"><?php _e('Save Results Pages', 'quiz-master-next'); ?></button>
284
- </form>
285
- <form method="post" action="" name="mlw_quiz_add_landing_form" style=" display:inline!important;">
286
- <input type='hidden' name='mlw_add_landing_page' value='confirmation' />
287
- <input type='hidden' name='mlw_add_landing_quiz_id' value='<?php echo $quiz_id; ?>' />
288
- <button id="new_landing_button" class="button" onclick="javascript: document.mlw_quiz_add_landing_form.submit();"><?php _e('Add New Results Page', 'quiz-master-next'); ?></button>
289
- </form>
290
- </div>
291
  <?php
292
  }
293
  ?>
1
  <?php
2
+ /**
3
+ * Creates the results page tab when editing quizzes.
4
+ *
5
+ * @package QSM
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
 
12
  /**
13
+ * Adds the Results Page tab to the Quiz Settings page.
14
+ *
15
+ * @since 6.1.0
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
 
23
  /**
24
+ * Adds the Results page content to the Results tab.
25
+ *
26
+ * @since 6.1.0
27
+ */
28
+ function qsm_options_results_tab_content() {
 
 
29
  global $wpdb;
30
  global $mlwQuizMasterNext;
31
+ $quiz_id = intval( $_GET['quiz_id'] );
32
+ $js_data = array(
33
+ 'quizID' => $quiz_id,
34
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
35
+ );
36
+ wp_enqueue_script( 'qsm_results_admin_script', plugins_url( '../../js/qsm-admin-results.js', __FILE__ ), array( 'jquery-ui-sortable', 'qmn_admin_js' ), $mlwQuizMasterNext->version );
37
+ wp_localize_script( 'qsm_results_admin_script', 'qsmResultsObject', $js_data );
38
+ wp_enqueue_editor();
39
+ wp_enqueue_media();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  ?>
41
+ <h2><?php esc_html_e( 'Results Pages', 'quiz-master-next' ); ?></h2>
42
+ <p>Need assistance with this tab? <a href="https://docs.quizandsurveymaster.com/article/25-setting-up-results-pages-and-thank-you-pages" target="_blank">Check out the documentation</a> for this tab!</p>
43
+
44
+ <!-- Template Variables Section -->
45
+ <section>
46
+ <h3 style="text-align: center;"><?php esc_html_e( 'Template Variables', 'quiz-master-next' ); ?></h3>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  <div class="template_list_holder">
48
  <div class="template_variable">
49
  <span class="template_name">%CONTACT_X%</span> - <?php _e( 'Value user entered into contact field. X is # of contact field. For example, first contact field would be %CONTACT_1%', 'quiz-master-next' ); ?>
117
  <?php do_action('qmn_template_variable_list'); ?>
118
  </div>
119
  <div style="clear:both;"></div>
120
+ </section>
121
+
122
+ <!-- Results Page Section -->
123
+ <section>
124
+ <h3>Your Pages</h3>
125
+ <button class="save-pages button-primary"><?php esc_html_e( 'Save Results Pages', 'quiz-master-next' ); ?></button>
126
+ <button class="add-new-page button"><?php esc_html_e( 'Add New Results Page', 'quiz-master-next' ); ?></button>
127
+ <div id="results-pages"></div>
128
+ <button class="save-pages button-primary"><?php esc_html_e( 'Save Results Pages', 'quiz-master-next' ); ?></button>
129
+ <button class="add-new-page button"><?php esc_html_e( 'Add New Results Page', 'quiz-master-next' ); ?></button>
130
+ </section>
131
+
132
+ <!-- Templates -->
133
+ <script type="text/template" id="tmpl-results-page">
134
+ <div class="results-page">
135
+ <header class="results-page-header">
136
+ <div><button class="delete-page-button"><span class="dashicons dashicons-trash"></span></button></div>
137
+ </header>
138
+ <main class="results-page-content">
139
+ <div class="results-page-when">
140
+ <div class="results-page-content-header">
141
+ <h4>When...</h4>
142
+ <p>Set conditions for when this page should be shown. Leave empty to set this as the default page.</p>
143
+ </div>
144
+ <div class="results-page-when-conditions">
145
+ <!-- Conditions go here. Review template below. -->
146
+ </div>
147
+ <button class="new-condition button"><?php esc_html_e( 'Add additional condition', 'quiz-master-next' ); ?></button>
148
+ </div>
149
+ <div class="results-page-show">
150
+ <div class="results-page-content-header">
151
+ <h4>...Show</h4>
152
+ <p>Create the results page that should be shown when the conditions are met.</p>
153
+ </div>
154
+ <textarea id="results-page-{{ data.id }}" class="results-page-template">{{{ data.page }}}</textarea>
155
+ <p>Or, redirect the user by entering the URL below:</p>
156
+ <input type="text" class="results-page-redirect" value="<# if ( data.redirect ) { #>{{ data.redirect }}<# } #>">
157
+ </div>
158
+ </main>
159
+ </div>
160
+ </script>
161
+
162
+ <script type="text/template" id="tmpl-results-page-condition">
163
+ <div class="results-page-condition">
164
+ <button class="delete-condition-button"><span class="dashicons dashicons-trash"></span></button>
165
+ <select class="results-page-condition-criteria">
166
+ <option value="points" <# if (data.criteria == 'points') { #>selected<# } #>>Total points earned</option>
167
+ <option value="score" <# if (data.criteria == 'score') { #>selected<# } #>>Correct score percentage</option>
168
+ <?php do_action( 'qsm_results_page_condition_criteria' ); ?>
169
+ </select>
170
+ <select class="results-page-condition-operator">
171
+ <option value="equal" <# if (data.operator == 'equal') { #>selected<# } #>>is equal to</option>
172
+ <option value="not-equal" <# if (data.operator == 'not-equal') { #>selected<# } #>>is not equal to</option>
173
+ <option value="greater-equal" <# if (data.operator == 'greater-equal') { #>selected<# } #>>is greater than or equal to</option>
174
+ <option value="greater" <# if (data.operator == 'greater') { #>selected<# } #>>is greater than</option>
175
+ <option value="less-equal" <# if (data.operator == 'less-equal') { #>selected<# } #>>is less than or equal to</option>
176
+ <option value="less" <# if (data.operator == 'less') { #>selected<# } #>>is less than</option>
177
+ <?php do_action( 'qsm_results_page_condition_operator' ); ?>
178
+ </select>
179
+ <input type="text" class="results-page-condition-value" value="{{ data.value }}">
180
+ </div>
181
+ </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  <?php
183
  }
184
  ?>
php/admin/options-page-style-tab.php CHANGED
@@ -55,53 +55,51 @@ function qsm_options_styling_tab_content() {
55
  }
56
  $registered_templates = $mlwQuizMasterNext->pluginHelper->get_quiz_templates();
57
  ?>
58
- <div id="tabs-7" class="mlw_tab_content">
59
- <script>
60
- function mlw_qmn_theme(theme)
61
- {
62
- document.getElementById('save_quiz_theme').value = theme;
63
- jQuery("div.mlw_qmn_themeBlockActive").toggleClass("mlw_qmn_themeBlockActive");
64
- jQuery("#mlw_qmn_theme_block_"+theme).toggleClass("mlw_qmn_themeBlockActive");
65
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
- </script>
68
- <form action='' method='post' name='quiz_style_form'>
69
- <input type='hidden' name='save_style_options' value='confirmation' />
70
- <input type='hidden' name='style_quiz_id' value='<?php echo esc_attr( $quiz_id ); ?>' />
71
- <input type='hidden' name='save_quiz_theme' id='save_quiz_theme' value='<?php echo esc_attr( $mlw_quiz_options->theme_selected ); ?>' />
72
- <h3><?php _e( 'Quiz Styles', 'quiz-master-next' ); ?></h3>
73
- <p><?php _e( 'Choose your style:', 'quiz-master-next' ); ?></p>
74
- <style>
75
- div.mlw_qmn_themeBlockActive {
76
- background-color: yellow;
77
- }
78
- </style>
79
- <div class="qsm-styles">
80
- <?php
81
- foreach ( $registered_templates as $slug => $template ) {
82
- ?>
83
- <div onclick="mlw_qmn_theme('<?php echo $slug; ?>');" id="mlw_qmn_theme_block_<?php echo $slug; ?>" class="qsm-info-widget <?php if ($mlw_quiz_options->theme_selected == $slug) {echo 'mlw_qmn_themeBlockActive';} ?>"><?php echo $template["name"]; ?></div>
84
- <?php
85
- }
86
  ?>
87
- <div onclick="mlw_qmn_theme('default');" id="mlw_qmn_theme_block_default" class="qsm-info-widget <?php if ($mlw_quiz_options->theme_selected == 'default') {echo 'mlw_qmn_themeBlockActive';} ?>"><?php _e('Custom', 'quiz-master-next'); ?></div>
88
- <script>
89
- mlw_qmn_theme('<?php echo $mlw_quiz_options->theme_selected; ?>');
90
- </script>
91
- </div>
92
- <button id="save_styles_button" class="button-primary"><?php _e('Save Quiz Style', 'quiz-master-next'); ?></button>
93
- <hr />
94
- <h3><?php _e('Custom Style CSS', 'quiz-master-next'); ?></h3>
95
- <p><?php _e('For help and guidance along with a list of different classes used in this plugin, please visit the following link:', 'quiz-master-next'); ?>
96
- <a target="_blank" href="https://docs.quizandsurveymaster.com/article/34-css-in-qsm">CSS in QSM</a></p>
97
- <table class="form-table">
98
- <tr>
99
- <td><textarea style="width: 100%; height: 700px;" id="quiz_css" name="quiz_css"><?php echo $mlw_quiz_options->quiz_stye; ?></textarea></td>
100
- </tr>
101
- </table>
102
- <button id="save_styles_button" class="button-primary"><?php _e('Save Quiz Style', 'quiz-master-next'); ?></button>
103
- </form>
104
- </div>
 
 
 
105
  <?php
106
  }
107
  ?>
55
  }
56
  $registered_templates = $mlwQuizMasterNext->pluginHelper->get_quiz_templates();
57
  ?>
58
+ <script>
59
+ function mlw_qmn_theme(theme)
60
+ {
61
+ document.getElementById('save_quiz_theme').value = theme;
62
+ jQuery("div.mlw_qmn_themeBlockActive").toggleClass("mlw_qmn_themeBlockActive");
63
+ jQuery("#mlw_qmn_theme_block_"+theme).toggleClass("mlw_qmn_themeBlockActive");
 
64
 
65
+ }
66
+ </script>
67
+ <form action='' method='post' name='quiz_style_form'>
68
+ <input type='hidden' name='save_style_options' value='confirmation' />
69
+ <input type='hidden' name='style_quiz_id' value='<?php echo esc_attr( $quiz_id ); ?>' />
70
+ <input type='hidden' name='save_quiz_theme' id='save_quiz_theme' value='<?php echo esc_attr( $mlw_quiz_options->theme_selected ); ?>' />
71
+ <h3><?php _e( 'Quiz Styles', 'quiz-master-next' ); ?></h3>
72
+ <p><?php _e( 'Choose your style:', 'quiz-master-next' ); ?></p>
73
+ <style>
74
+ div.mlw_qmn_themeBlockActive {
75
+ background-color: yellow;
76
  }
77
+ </style>
78
+ <div class="qsm-styles">
79
+ <?php
80
+ foreach ( $registered_templates as $slug => $template ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  ?>
82
+ <div onclick="mlw_qmn_theme('<?php echo $slug; ?>');" id="mlw_qmn_theme_block_<?php echo $slug; ?>" class="qsm-info-widget <?php if ($mlw_quiz_options->theme_selected == $slug) {echo 'mlw_qmn_themeBlockActive';} ?>"><?php echo $template["name"]; ?></div>
83
+ <?php
84
+ }
85
+ ?>
86
+ <div onclick="mlw_qmn_theme('default');" id="mlw_qmn_theme_block_default" class="qsm-info-widget <?php if ($mlw_quiz_options->theme_selected == 'default') {echo 'mlw_qmn_themeBlockActive';} ?>"><?php _e('Custom', 'quiz-master-next'); ?></div>
87
+ <script>
88
+ mlw_qmn_theme('<?php echo $mlw_quiz_options->theme_selected; ?>');
89
+ </script>
90
+ </div>
91
+ <button id="save_styles_button" class="button-primary"><?php _e('Save Quiz Style', 'quiz-master-next'); ?></button>
92
+ <hr />
93
+ <h3><?php _e('Custom Style CSS', 'quiz-master-next'); ?></h3>
94
+ <p><?php _e('For help and guidance along with a list of different classes used in this plugin, please visit the following link:', 'quiz-master-next'); ?>
95
+ <a target="_blank" href="https://docs.quizandsurveymaster.com/article/34-css-in-qsm">CSS in QSM</a></p>
96
+ <table class="form-table">
97
+ <tr>
98
+ <td><textarea style="width: 100%; height: 700px;" id="quiz_css" name="quiz_css"><?php echo $mlw_quiz_options->quiz_stye; ?></textarea></td>
99
+ </tr>
100
+ </table>
101
+ <button id="save_styles_button" class="button-primary"><?php _e('Save Quiz Style', 'quiz-master-next'); ?></button>
102
+ </form>
103
  <?php
104
  }
105
  ?>
php/admin/quiz-options-page.php CHANGED
@@ -1,33 +1,41 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
 
 
3
 
4
  /**
5
- * This function allows for the editing of quiz options.
6
- *
7
- * @param type description
8
- * @return void
9
- * @since 4.4.0
10
- */
11
  function qsm_generate_quiz_options() {
12
 
13
- // Check if current user can
14
- if ( ! current_user_can('moderate_comments') ) {
15
  return;
16
  }
17
 
18
  global $wpdb;
19
  global $mlwQuizMasterNext;
 
20
  $quiz_name = '';
21
 
22
- // Get registered tabs for the options page and set current tab
23
- $tab_array = $mlwQuizMasterNext->pluginHelper->get_settings_tabs();
24
- $active_tab = strtolower(str_replace( " ", "-", isset( $_GET[ 'tab' ] ) ? stripslashes( $_GET[ 'tab' ] ) : __( 'Questions', 'quiz-master-next' )));
25
 
26
  // Prepares quiz.
27
  $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0;
28
- if ( isset( $_GET["quiz_id"] ) ) {
29
  $quiz_name = $wpdb->get_var( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $quiz_id ) );
30
- $mlwQuizMasterNext->pluginHelper->prepare_quiz( $_GET["quiz_id"] );
31
  }
32
 
33
  wp_enqueue_script( 'jquery' );
@@ -38,66 +46,80 @@ function qsm_generate_quiz_options() {
38
  wp_enqueue_script( 'jquery-ui-tabs' );
39
  wp_enqueue_script( 'jquery-effects-blind' );
40
  wp_enqueue_script( 'jquery-effects-explode' );
 
 
 
41
  wp_enqueue_style( 'qmn_jquery_redmond_theme', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/redmond/jquery-ui.css' );
42
  wp_enqueue_script( 'math_jax', '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML' );
43
  ?>
44
- <style>
45
- .mlw_tab_content {
46
- padding: 20px 20px 20px 20px;
47
- margin: 20px 20px 20px 20px;
48
- }
49
- </style>
50
  <div class="wrap">
51
- <div class='mlw_quiz_options'>
52
- <h1><?php echo $quiz_name; ?></h1>
53
- <?php
54
- // Put all output from tab into ob_get_contents below.
55
- ob_start();
56
 
57
- // If the quiz is set and not empty
58
- if ( ! empty( $quiz_id ) ) {
59
- ?>
60
- <h2 class="nav-tab-wrapper">
61
- <?php
62
- // Cycle through registered tabs to create navigation
63
- foreach( $tab_array as $tab ) {
64
- $active_class = '';
65
- if ( $active_tab == $tab['slug'] ) {
66
- $active_class = 'nav-tab-active';
67
- }
68
- echo "<a href=\"?page=mlw_quiz_options&quiz_id=$quiz_id&tab=".$tab['slug']."\" class=\"nav-tab $active_class\">".$tab['title']."</a>";
69
- }
70
  ?>
71
- </h2>
72
- <div class="mlw_tab_content">
73
- <?php
74
- // Cycle through tabs looking for current tab to create tab's content
75
- foreach( $tab_array as $tab ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  if ( $active_tab == $tab['slug'] ) {
77
  call_user_func( $tab['function'] );
78
  }
79
  }
 
 
 
 
80
  ?>
81
- </div>
82
- <?php
83
- } else {
 
 
 
 
 
 
 
84
  ?>
85
- <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
86
- <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
87
- <strong><?php _e('Error!', 'quiz-master-next'); ?></strong> <?php _e('Please go to the quizzes page and click on the Edit link from the quiz you wish to edit.', 'quiz-master-next'); ?></p>
 
88
  </div>
89
  <?php
90
- }
91
- $mlw_output = ob_get_contents();
92
- ob_end_clean();
93
-
94
- // Shows alerts, ads, then tab content
95
- $mlwQuizMasterNext->alertManager->showAlerts();
96
- echo mlw_qmn_show_adverts();
97
- echo $mlw_output;
98
- ?>
99
- </div>
100
  </div>
 
 
 
 
 
 
 
 
 
101
  <?php
102
  }
103
  ?>
1
  <?php
2
+ /**
3
+ * Creates the view for all tabs for editing the quiz.
4
+ *
5
+ * @package QSM
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
 
12
  /**
13
+ * This function allows for the editing of quiz options.
14
+ *
15
+ * @return void
16
+ * @since 4.4.0
17
+ */
 
18
  function qsm_generate_quiz_options() {
19
 
20
+ // Checks if current user can.
21
+ if ( ! current_user_can( 'moderate_comments' ) ) {
22
  return;
23
  }
24
 
25
  global $wpdb;
26
  global $mlwQuizMasterNext;
27
+
28
  $quiz_name = '';
29
 
30
+ // Gets registered tabs for the options page and set current tab.
31
+ $tab_array = $mlwQuizMasterNext->pluginHelper->get_settings_tabs();
32
+ $active_tab = strtolower( str_replace( ' ', '-', isset( $_GET[ 'tab' ] ) ? stripslashes( $_GET[ 'tab' ] ) : __( 'Questions', 'quiz-master-next' ) ) );
33
 
34
  // Prepares quiz.
35
  $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0;
36
+ if ( isset( $_GET['quiz_id'] ) ) {
37
  $quiz_name = $wpdb->get_var( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $quiz_id ) );
38
+ $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz_id );
39
  }
40
 
41
  wp_enqueue_script( 'jquery' );
46
  wp_enqueue_script( 'jquery-ui-tabs' );
47
  wp_enqueue_script( 'jquery-effects-blind' );
48
  wp_enqueue_script( 'jquery-effects-explode' );
49
+
50
+ wp_enqueue_script( 'qmn_admin_js', plugins_url( '../../js/admin.js', __FILE__ ), array( 'backbone', 'underscore', 'wp-util' ), $mlwQuizMasterNext->version, true );
51
+ wp_enqueue_style( 'qsm_admin_style', plugins_url( '../../css/qsm-admin.css', __FILE__ ), array(), $mlwQuizMasterNext->version );
52
  wp_enqueue_style( 'qmn_jquery_redmond_theme', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/redmond/jquery-ui.css' );
53
  wp_enqueue_script( 'math_jax', '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML' );
54
  ?>
 
 
 
 
 
 
55
  <div class="wrap">
56
+ <div class='mlw_quiz_options'>
57
+ <h1><?php echo $quiz_name; ?></h1>
58
+ <?php
59
+ // Puts all output from tab into ob_get_contents below.
60
+ ob_start();
61
 
62
+ // If the quiz is set and not empty.
63
+ if ( ! empty( $quiz_id ) ) {
 
 
 
 
 
 
 
 
 
 
 
64
  ?>
65
+ <nav class="nav-tab-wrapper">
66
+ <?php
67
+ // Cycles through registered tabs to create navigation.
68
+ foreach ( $tab_array as $tab ) {
69
+ $active_class = '';
70
+ if ( $active_tab == $tab['slug'] ) {
71
+ $active_class = 'nav-tab-active';
72
+ }
73
+ ?>
74
+ <a href="?page=mlw_quiz_options&quiz_id=<?php echo esc_attr( $quiz_id ); ?>&tab=<?php echo esc_attr( $tab['slug'] ); ?>" class="nav-tab <?php echo esc_attr( $active_class ); ?>"><?php echo esc_html( $tab['title'] ); ?></a>
75
+ <?php
76
+ }
77
+ ?>
78
+ </nav>
79
+ <div class="qsm_tab_content">
80
+ <?php
81
+ // Cycles through tabs looking for current tab to create tab's content.
82
+ foreach ( $tab_array as $tab ) {
83
  if ( $active_tab == $tab['slug'] ) {
84
  call_user_func( $tab['function'] );
85
  }
86
  }
87
+ ?>
88
+ </div>
89
+ <?php
90
+ } else {
91
  ?>
92
+ <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
93
+ <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
94
+ <strong><?php esc_html_e( 'Error!', 'quiz-master-next' ); ?></strong> <?php esc_html_e( 'Please go to the quizzes page and click on the Edit link from the quiz you wish to edit.', 'quiz-master-next' ); ?></p>
95
+ </div>
96
+ <?php
97
+ }
98
+ $mlw_output = ob_get_contents();
99
+ ob_end_clean();
100
+
101
+ // Shows alerts, ads, then tab content.
102
  ?>
103
+ <div class="qsm-alerts">
104
+ <?php
105
+ $mlwQuizMasterNext->alertManager->showAlerts();
106
+ ?>
107
  </div>
108
  <?php
109
+ qsm_show_adverts();
110
+ echo $mlw_output;
111
+ ?>
112
+ </div>
 
 
 
 
 
 
113
  </div>
114
+
115
+ <!-- Backbone Views -->
116
+
117
+ <!-- View for Notices -->
118
+ <script type="text/template" id="tmpl-notice">
119
+ <div class="notice notice-large notice-{{data.type}}">
120
+ <p>{{data.message}}</p>
121
+ </div>
122
+ </script>
123
  <?php
124
  }
125
  ?>
php/admin/quizzes-page.php CHANGED
@@ -5,7 +5,9 @@
5
  * @package QSM
6
  */
7
 
8
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
9
 
10
  /**
11
  * Generates the quizzes and surveys page
@@ -87,7 +89,7 @@ function qsm_generate_quizzes_surveys_page() {
87
 
88
  // Load quiz posts.
89
  $post_to_quiz_array = array();
90
- $my_query = new WP_Query( array(
91
  'post_type' => 'quiz',
92
  'posts_per_page' => -1,
93
  'post_status' => 'publish',
@@ -138,7 +140,7 @@ function qsm_generate_quizzes_surveys_page() {
138
  wp_localize_script( 'qsm_admin_script', 'qsmQuizObject', $quiz_json_array );
139
  ?>
140
  <div class="wrap qsm-quizes-page">
141
- <h1><?php _e( 'Quizzes/Surveys', 'quiz-master-next' ); ?><a id="new_quiz_button" href="#" class="add-new-h2"><?php _e( 'Add New', 'quiz-master-next' ); ?></a></h1>
142
  <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
143
  <?php
144
  if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
@@ -152,9 +154,9 @@ function qsm_generate_quizzes_surveys_page() {
152
  <div class="qsm-quizzes-page-content">
153
  <div class="<?php if ( 'false' != get_option( 'mlw_advert_shows' ) ) { echo 'qsm-quiz-page-wrapper-with-ads'; } else { echo 'qsm-quiz-page-wrapper'; } ?>">
154
  <p class="search-box">
155
- <label class="screen-reader-text" for="quiz_search"><?php _e( 'Search', 'quiz-master-next' ); ?></label>
156
  <input type="search" id="quiz_search" name="quiz_search" value="">
157
- <a href="#" class="button"><?php _e( 'Search', 'quiz-master-next' ); ?></a>
158
  </p>
159
  <div class="tablenav top">
160
  <div class="tablenav-pages">
@@ -165,12 +167,12 @@ function qsm_generate_quizzes_surveys_page() {
165
  <table class="widefat">
166
  <thead>
167
  <tr>
168
- <th><?php _e( 'Name', 'quiz-master-next' ); ?></th>
169
- <th><?php _e( 'URL', 'quiz-master-next' ); ?></th>
170
- <th><?php _e( 'Shortcode', 'quiz-master-next' ); ?></th>
171
- <th><?php _e( 'Link Shortcode', 'quiz-master-next' ); ?></th>
172
- <th><?php _e( 'Views/Taken', 'quiz-master-next' ); ?></th>
173
- <th><?php _e( 'Last Modified', 'quiz-master-next' ); ?></th>
174
  </tr>
175
  </thead>
176
  <tbody id="the-list">
@@ -178,12 +180,12 @@ function qsm_generate_quizzes_surveys_page() {
178
  </tbody>
179
  <tfoot>
180
  <tr>
181
- <th><?php _e( 'Name', 'quiz-master-next' ); ?></th>
182
- <th><?php _e( 'URL', 'quiz-master-next' ); ?></th>
183
- <th><?php _e( 'Shortcode', 'quiz-master-next' ); ?></th>
184
- <th><?php _e( 'Link Shortcode', 'quiz-master-next' ); ?></th>
185
- <th><?php _e( 'Views/Taken', 'quiz-master-next' ); ?></th>
186
- <th><?php _e( 'Last Modified', 'quiz-master-next' ); ?></th>
187
  </tr>
188
  </tfoot>
189
  </table>
@@ -192,19 +194,19 @@ function qsm_generate_quizzes_surveys_page() {
192
  if ( 'true' == get_option( 'mlw_advert_shows' ) ) {
193
  ?>
194
  <div class="qsm-news-ads">
195
- <h3 class="qsm-news-ads-title"><?php _e( 'QSM News', 'quiz-master-next' ); ?></h3>
196
  <div class="qsm-info-widget">
197
  <h3>Keep your WordPress site healthy and secure!</h3>
198
  <p>Easily monitor your WordPress sites to ensure they stay up, healthy, and secure with our new WordPress plugin, WP Health!</p>
199
  <a target="_blank" href="http://bit.ly/2Mr2SqC" class="button-primary"><?php esc_html_e( 'Learn More', 'quiz-master-next' ); ?></a>
200
  </div>
201
  <div class="qsm-info-widget">
202
- <h3><?php _e( 'Subscribe to our newsletter!', 'quiz-master-next' ); ?></h3>
203
- <p><?php _e( 'Join our mailing list to learn about our newest features, receive email-only promotions, receive tips and guides, and more!', 'quiz-master-next' ); ?></p>
204
  <a target="_blank" href="http://quizandsurveymaster.com/subscribe-to-our-newsletter/?utm_source=qsm-quizzes-page&utm_medium=plugin&utm_campaign=qsm_plugin&utm_content=subscribe-to-newsletter" class="button-primary"><?php _e( 'Subscribe Now', 'quiz-master-next' ); ?></a>
205
  </div>
206
  <?php
207
- $qmn_rss = array();
208
  $qmn_feed = fetch_feed( 'https://quizandsurveymaster.com/feed' );
209
  if ( ! is_wp_error( $qmn_feed ) ) {
210
  $qmn_feed_items = $qmn_feed->get_items( 0, 5 );
5
  * @package QSM
6
  */
7
 
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
 
12
  /**
13
  * Generates the quizzes and surveys page
89
 
90
  // Load quiz posts.
91
  $post_to_quiz_array = array();
92
+ $my_query = new WP_Query( array(
93
  'post_type' => 'quiz',
94
  'posts_per_page' => -1,
95
  'post_status' => 'publish',
140
  wp_localize_script( 'qsm_admin_script', 'qsmQuizObject', $quiz_json_array );
141
  ?>
142
  <div class="wrap qsm-quizes-page">
143
+ <h1><?php esc_html_e( 'Quizzes/Surveys', 'quiz-master-next' ); ?><a id="new_quiz_button" href="#" class="add-new-h2"><?php _e( 'Add New', 'quiz-master-next' ); ?></a></h1>
144
  <?php $mlwQuizMasterNext->alertManager->showAlerts(); ?>
145
  <?php
146
  if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
154
  <div class="qsm-quizzes-page-content">
155
  <div class="<?php if ( 'false' != get_option( 'mlw_advert_shows' ) ) { echo 'qsm-quiz-page-wrapper-with-ads'; } else { echo 'qsm-quiz-page-wrapper'; } ?>">
156
  <p class="search-box">
157
+ <label class="screen-reader-text" for="quiz_search"><?php esc_html_e( 'Search', 'quiz-master-next' ); ?></label>
158
  <input type="search" id="quiz_search" name="quiz_search" value="">
159
+ <a href="#" class="button"><?php esc_html_e( 'Search', 'quiz-master-next' ); ?></a>
160
  </p>
161
  <div class="tablenav top">
162
  <div class="tablenav-pages">
167
  <table class="widefat">
168
  <thead>
169
  <tr>
170
+ <th><?php esc_html_e( 'Name', 'quiz-master-next' ); ?></th>
171
+ <th><?php esc_html_e( 'URL', 'quiz-master-next' ); ?></th>
172
+ <th><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></th>
173
+ <th><?php esc_html_e( 'Link Shortcode', 'quiz-master-next' ); ?></th>
174
+ <th><?php esc_html_e( 'Views/Taken', 'quiz-master-next' ); ?></th>
175
+ <th><?php esc_html_e( 'Last Modified', 'quiz-master-next' ); ?></th>
176
  </tr>
177
  </thead>
178
  <tbody id="the-list">
180
  </tbody>
181
  <tfoot>
182
  <tr>
183
+ <th><?php esc_html_e( 'Name', 'quiz-master-next' ); ?></th>
184
+ <th><?php esc_html_e( 'URL', 'quiz-master-next' ); ?></th>
185
+ <th><?php esc_html_e( 'Shortcode', 'quiz-master-next' ); ?></th>
186
+ <th><?php esc_html_e( 'Link Shortcode', 'quiz-master-next' ); ?></th>
187
+ <th><?php esc_html_e( 'Views/Taken', 'quiz-master-next' ); ?></th>
188
+ <th><?php esc_html_e( 'Last Modified', 'quiz-master-next' ); ?></th>
189
  </tr>
190
  </tfoot>
191
  </table>
194
  if ( 'true' == get_option( 'mlw_advert_shows' ) ) {
195
  ?>
196
  <div class="qsm-news-ads">
197
+ <h3 class="qsm-news-ads-title"><?php esc_html_e( 'QSM News', 'quiz-master-next' ); ?></h3>
198
  <div class="qsm-info-widget">
199
  <h3>Keep your WordPress site healthy and secure!</h3>
200
  <p>Easily monitor your WordPress sites to ensure they stay up, healthy, and secure with our new WordPress plugin, WP Health!</p>
201
  <a target="_blank" href="http://bit.ly/2Mr2SqC" class="button-primary"><?php esc_html_e( 'Learn More', 'quiz-master-next' ); ?></a>
202
  </div>
203
  <div class="qsm-info-widget">
204
+ <h3><?php esc_html_e( 'Subscribe to our newsletter!', 'quiz-master-next' ); ?></h3>
205
+ <p><?php esc_html_e( 'Join our mailing list to learn about our newest features, receive email-only promotions, receive tips and guides, and more!', 'quiz-master-next' ); ?></p>
206
  <a target="_blank" href="http://quizandsurveymaster.com/subscribe-to-our-newsletter/?utm_source=qsm-quizzes-page&utm_medium=plugin&utm_campaign=qsm_plugin&utm_content=subscribe-to-newsletter" class="button-primary"><?php _e( 'Subscribe Now', 'quiz-master-next' ); ?></a>
207
  </div>
208
  <?php
209
+ $qmn_rss = array();
210
  $qmn_feed = fetch_feed( 'https://quizandsurveymaster.com/feed' );
211
  if ( ! is_wp_error( $qmn_feed ) ) {
212
  $qmn_feed_items = $qmn_feed->get_items( 0, 5 );
php/admin/settings-page.php CHANGED
@@ -42,7 +42,7 @@ class QMNGlobalSettingsPage {
42
  */
43
  public function init() {
44
  register_setting( 'qmn-settings-group', 'qmn-settings' );
45
- add_settings_section( 'qmn-global-section', __( 'Main Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qmn_global_settings' );
46
  add_settings_field( 'usage-tracker', __( 'Allow Usage Tracking?', 'quiz-master-next' ), array( $this, 'usage_tracker_field' ), 'qmn_global_settings', 'qmn-global-section' );
47
  add_settings_field( 'ip-collection', __( 'Disable collecting and storing IP addresses?', 'quiz-master-next' ), array( $this, 'ip_collection_field' ), 'qmn_global_settings', 'qmn-global-section' );
48
  add_settings_field( 'cpt-search', __( 'Disable Quiz Posts From Being Searched?', 'quiz-master-next' ), array( $this, 'cpt_search_field' ), 'qmn_global_settings', 'qmn-global-section' );
@@ -50,6 +50,8 @@ class QMNGlobalSettingsPage {
50
  add_settings_field( 'cpt-slug', __( 'Quiz Url Slug', 'quiz-master-next' ), array( $this, 'cpt_slug_field' ), 'qmn_global_settings', 'qmn-global-section' );
51
  add_settings_field( 'plural-name', __( 'Post Type Plural Name (Shown in various places such as on archive pages)', 'quiz-master-next' ), array( $this, 'plural_name_field' ), 'qmn_global_settings', 'qmn-global-section' );
52
  add_settings_field( 'facebook-app-id', __( 'Facebook App Id', 'quiz-master-next' ), array( $this, 'facebook_app_id' ), 'qmn_global_settings', 'qmn-global-section' );
 
 
53
  add_settings_field( 'results-details', __( 'Template For Admin Results Details', 'quiz-master-next' ), array( $this, 'results_details_template' ), 'qmn_global_settings', 'qmn-global-section' );
54
  }
55
 
@@ -69,6 +71,40 @@ class QMNGlobalSettingsPage {
69
  }
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * Generates Setting Field For App Id
74
  *
42
  */
43
  public function init() {
44
  register_setting( 'qmn-settings-group', 'qmn-settings' );
45
+ add_settings_section( 'qmn-global-section', __( 'Main Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qmn_global_settings' );
46
  add_settings_field( 'usage-tracker', __( 'Allow Usage Tracking?', 'quiz-master-next' ), array( $this, 'usage_tracker_field' ), 'qmn_global_settings', 'qmn-global-section' );
47
  add_settings_field( 'ip-collection', __( 'Disable collecting and storing IP addresses?', 'quiz-master-next' ), array( $this, 'ip_collection_field' ), 'qmn_global_settings', 'qmn-global-section' );
48
  add_settings_field( 'cpt-search', __( 'Disable Quiz Posts From Being Searched?', 'quiz-master-next' ), array( $this, 'cpt_search_field' ), 'qmn_global_settings', 'qmn-global-section' );
50
  add_settings_field( 'cpt-slug', __( 'Quiz Url Slug', 'quiz-master-next' ), array( $this, 'cpt_slug_field' ), 'qmn_global_settings', 'qmn-global-section' );
51
  add_settings_field( 'plural-name', __( 'Post Type Plural Name (Shown in various places such as on archive pages)', 'quiz-master-next' ), array( $this, 'plural_name_field' ), 'qmn_global_settings', 'qmn-global-section' );
52
  add_settings_field( 'facebook-app-id', __( 'Facebook App Id', 'quiz-master-next' ), array( $this, 'facebook_app_id' ), 'qmn_global_settings', 'qmn-global-section' );
53
+ add_settings_field( 'from-name', __( 'From Name (The name emails come from)', 'quiz-master-next' ), array( $this, 'from_name' ), 'qmn_global_settings', 'qmn-global-section' );
54
+ add_settings_field( 'from-email', __( 'From Email (The email address that emails come from)', 'quiz-master-next' ), array( $this, 'from_email' ), 'qmn_global_settings', 'qmn-global-section' );
55
  add_settings_field( 'results-details', __( 'Template For Admin Results Details', 'quiz-master-next' ), array( $this, 'results_details_template' ), 'qmn_global_settings', 'qmn-global-section' );
56
  }
57
 
71
  }
72
  }
73
 
74
+ /**
75
+ * Generates Setting Field For From Email
76
+ *
77
+ * @since 6.2.0
78
+ * @return void
79
+ */
80
+ public function from_email() {
81
+ $settings = (array) get_option( 'qmn-settings' );
82
+ $from_email = get_option( 'admin_email', '' );
83
+ if ( isset( $settings['from_email'] ) ) {
84
+ $from_email = $settings['from_email'];
85
+ }
86
+ ?>
87
+ <input type='email' name='qmn-settings[from_email]' id='qmn-settings[from_email]' value='<?php echo esc_attr( $from_email ); ?>' />
88
+ <?php
89
+ }
90
+
91
+ /**
92
+ * Generates Setting Field For From Name
93
+ *
94
+ * @since 6.2.0
95
+ * @return void
96
+ */
97
+ public function from_name() {
98
+ $settings = (array) get_option( 'qmn-settings' );
99
+ $from_name = get_bloginfo( 'name' );
100
+ if ( isset( $settings['from_name'] ) ) {
101
+ $from_name = $settings['from_name'];
102
+ }
103
+ ?>
104
+ <input type='text' name='qmn-settings[from_name]' id='qmn-settings[from_name]' value='<?php echo esc_attr( $from_name ); ?>' />
105
+ <?php
106
+ }
107
+
108
  /**
109
  * Generates Setting Field For App Id
110
  *
php/admin/stats-page.php CHANGED
@@ -27,7 +27,7 @@ function qmn_generate_stats_page()
27
  ?>
28
  <div class="wrap">
29
  <h2><?php _e('Quiz/Survey Statistics', 'quiz-master-next'); ?></h2>
30
- <?php echo mlw_qmn_show_adverts(); ?>
31
  <h2 class="nav-tab-wrapper">
32
  <?php
33
  foreach($tab_array as $tab)
27
  ?>
28
  <div class="wrap">
29
  <h2><?php _e('Quiz/Survey Statistics', 'quiz-master-next'); ?></h2>
30
+ <?php qsm_show_adverts(); ?>
31
  <h2 class="nav-tab-wrapper">
32
  <?php
33
  foreach($tab_array as $tab)
php/admin/tools-page.php CHANGED
@@ -1,217 +1,197 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
3
- /*
4
- This page creates the main dashboard for the Quiz And Survey Master plugin
5
- */
 
 
 
6
 
7
 
8
  /**
9
- * Generates all of the quiz tools that are used
10
- *
11
- * Long Description
12
- *
13
- * @param type description
14
- * @return type description
15
- * @since 4.4.0
16
- */
17
- function mlw_generate_quiz_tools()
18
- {
19
- if ( !current_user_can('moderate_comments') )
20
- {
21
  return;
22
  }
23
- add_meta_box("qmn_restore_box", 'Restore Quiz', "qmn_restore_function", "quiz_wpss");
24
- add_meta_box("qmn_audit_box", 'Audit Trail', "mlw_tools_box", "quiz_wpss");
25
-
26
- wp_enqueue_script( 'jquery' );
27
- wp_enqueue_script( 'jquery-ui-core' );
28
- wp_enqueue_script( 'jquery-ui-dialog' );
29
- wp_enqueue_script( 'jquery-ui-button' );
30
- wp_enqueue_script( 'jquery-ui-accordion' );
31
- wp_enqueue_script( 'jquery-ui-tooltip' );
32
- wp_enqueue_script( 'jquery-ui-tabs' );
33
- wp_enqueue_script( 'jquery-effects-blind' );
34
- wp_enqueue_script( 'jquery-effects-explode' );
35
- wp_enqueue_style( 'qmn_jquery_redmond_theme', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/redmond/jquery-ui.css' );
36
  ?>
37
-
38
- <script type="text/javascript">
39
- var $j = jQuery.noConflict();
40
- // increase the default animation speed to exaggerate the effect
41
- $j.fx.speeds._default = 1000;
42
-
43
- $j(function() {
44
- $j("button, #prev_page, #next_page").button();
45
-
46
- });
47
- </script>
48
- <style type="text/css">
49
- textarea{
50
- border-color:#000000;
51
- color:#3300CC;
52
- cursor:hand;
53
- }
54
- p em {
55
- padding-left: 1em;
56
- color: #555;
57
- font-weight: bold;
58
- }
59
- </style>
60
  <div class="wrap">
61
- <h2><?php _e('Tools', 'quiz-master-next'); ?></h2>
62
 
63
  <div style="float:left; width:100%;" class="inner-sidebar1">
64
- <?php do_meta_boxes('quiz_wpss','advanced',null); ?>
65
  </div>
66
 
67
  <div style="clear:both"></div>
68
 
69
- <?php echo mlw_qmn_show_adverts(); ?>
70
 
71
  </div>
72
  <?php
73
  }
74
 
75
  /**
76
- * Allows the admin to restore a deleted quiz
77
- *
78
- * @return void
79
- * @since 4.4.0
80
- */
81
- function qmn_restore_function()
82
- {
83
  global $wpdb;
84
- if (isset($_POST["restore_quiz"]))
85
- {
 
86
  $restore = $wpdb->update(
87
  $wpdb->prefix.'mlw_quizzes',
88
  array(
89
- 'deleted' => 0
90
  ),
91
  array(
92
- 'quiz_id' => intval($_POST["restore_quiz"])
93
  ),
94
  array(
95
- '%d'
96
  ),
97
  array(
98
- '%d'
99
  )
100
  );
101
- if (!$restore)
102
- {
103
- echo "<span style='color:red;'>".__("There has been an error! Please try again.", "quiz-master-next")."</span>";
104
- }
105
- else
106
- {
107
- $my_query = new WP_Query( array('post_type' => 'quiz', 'meta_key' => 'quiz_id', 'meta_value' => intval($_POST["restore_quiz"])) );
108
- if( $my_query->have_posts() )
109
- {
110
- while( $my_query->have_posts() )
111
- {
112
- $my_query->the_post();
 
 
113
  $my_post = array(
114
- 'ID' => get_the_ID(),
115
- 'post_status' => 'publish'
116
- );
117
  wp_update_post( $my_post );
118
- }
119
  }
120
  wp_reset_postdata();
121
- echo "<span style='color:red;'>".__("Quiz Has Been Restored!", "quiz-master-next")."</span>";
 
 
122
  }
123
  }
124
- $quizzes = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."mlw_quizzes WHERE deleted=1");
125
  ?>
126
- <h3><?php _e("Choose a quiz in the drop down and then click the button to restore a deleted quiz.", "quiz-master-next"); ?></h3>
127
  <form action='' method="post">
128
  <select name="restore_quiz">
129
  <?php
130
- foreach($quizzes as $quiz)
131
- {
132
- echo "<option value='".$quiz->quiz_id."'>".$quiz->quiz_name."</option>";
 
133
  }
134
  ?>
135
  </select>
136
- <input type="submit" value="<?php _e('Restore Quiz', "quiz-master-next"); ?>" class="button" />
137
  </form>
138
  <?php
139
  }
140
 
141
  /**
142
- * Creates the tools page that is used to make audits on the quizzes.
143
- *
144
- * @return void
145
- * @since 4.4.0
146
- */
147
- function mlw_tools_box()
148
- {
149
  global $wpdb;
150
- $mlw_qmn_table_limit = 30;
151
- $mlw_qmn_audit_count = $wpdb->get_var( "SELECT COUNT(trail_id) FROM " . $wpdb->prefix . "mlw_qm_audit_trail" );
152
-
153
- if( isset($_GET{'mlw_audit_page'} ) )
154
- {
155
- $mlw_qmn_audit_page = $_GET{'mlw_audit_page'} + 1;
156
- $mlw_qmn_audit_begin = $mlw_qmn_table_limit * $mlw_qmn_audit_page ;
 
 
 
 
157
  }
158
- else
159
- {
160
- $mlw_qmn_audit_page = 0;
161
- $mlw_qmn_audit_begin = 0;
162
- }
163
- $mlw_qmn_audit_left = $mlw_qmn_audit_count - ($mlw_qmn_audit_page * $mlw_qmn_table_limit);
164
-
165
  $audit_trails = $wpdb->get_results( $wpdb->prepare( "SELECT trail_id, action_user, action, time
166
- FROM " . $wpdb->prefix . "mlw_qm_audit_trail
167
- ORDER BY trail_id DESC LIMIT %d, %d", $mlw_qmn_audit_begin, $mlw_qmn_table_limit ) );
 
 
168
 
169
- if( $mlw_qmn_audit_page > 0 )
170
- {
171
- $mlw_qmn_previous_page = $mlw_qmn_audit_page - 2;
172
- echo "<a id=\"prev_page\" href=\"?page=mlw_quiz_tools&&mlw_audit_page=$mlw_qmn_previous_page\">".sprintf(__('Previous %s Audits','quiz-master-next'),$mlw_qmn_table_limit)."</a>";
173
- if( $mlw_qmn_audit_left > $mlw_qmn_table_limit )
174
- {
175
- echo "<a id=\"next_page\" href=\"?page=mlw_quiz_tools&&mlw_audit_page=$mlw_qmn_audit_page\">".sprintf(__('Next %s Audits','quiz-master-next'),$mlw_qmn_table_limit)."</a>";
 
 
 
 
 
 
 
176
  }
177
- }
178
- else if( $mlw_qmn_audit_page == 0 )
179
- {
180
- if( $mlw_qmn_audit_left > $mlw_qmn_table_limit )
181
- {
182
- echo "<a id=\"next_page\" href=\"?page=mlw_quiz_tools&&mlw_audit_page=$mlw_qmn_audit_page\">".sprintf(__('Next %s Audits','quiz-master-next'),$mlw_qmn_table_limit)."</a>";
183
- }
184
- }
185
- else if( $mlw_qmn_audit_left < $mlw_qmn_table_limit )
186
- {
187
- $mlw_qmn_previous_page = $mlw_qmn_audit_page - 2;
188
- echo "<a id=\"prev_page\" href=\"?page=mlw_quiz_tools&&mlw_audit_page=$mlw_qmn_previous_page\">".sprintf(__('Previous %s Audits','quiz-master-next'),$mlw_qmn_table_limit)."</a>";
 
 
 
189
  }
190
  ?>
191
  <table class=widefat>
192
  <thead>
193
  <tr>
194
  <th>ID</th>
195
- <th><?php _e('User','quiz-master-next'); ?></th>
196
- <th><?php _e('Action','quiz-master-next'); ?></th>
197
- <th><?php _e('Time','quiz-master-next'); ?></th>
198
  </tr>
199
  </thead>
200
  <tbody id="the-list">
201
-
202
- <?php
203
- $alternate = "";
204
- foreach($audit_trails as $quote_data) {
205
- if($alternate) $alternate = "";
206
- else $alternate = " class=\"alternate\"";
207
- echo "<tr{$alternate}>";
208
- echo "<td>" . $quote_data->trail_id . "</td>";
209
- echo "<td>" . $quote_data->action_user . "</td>";
210
- echo "<td>" . $quote_data->action ."</td>";
211
- echo "<td>" . $quote_data->time . "</td>";
212
- echo "</tr>";
213
- }
214
- ?>
 
 
215
  </tbody>
216
  </table>
217
  <?php
1
  <?php
2
+ /**
3
+ * Generates the content for the tools page.
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
 
10
 
11
  /**
12
+ * Generates all of the quiz tools that are used
13
+ *
14
+ * @return void
15
+ * @since 6.2.0
16
+ */
17
+ function qsm_generate_quiz_tools() {
18
+ if ( ! current_user_can( 'moderate_comments' ) ) {
 
 
 
 
 
19
  return;
20
  }
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
  <div class="wrap">
25
+ <h2><?php esc_html_e('Tools', 'quiz-master-next'); ?></h2>
26
 
27
  <div style="float:left; width:100%;" class="inner-sidebar1">
28
+ <?php do_meta_boxes( 'quiz_wpss', 'advanced', null ); ?>
29
  </div>
30
 
31
  <div style="clear:both"></div>
32
 
33
+ <?php qsm_show_adverts(); ?>
34
 
35
  </div>
36
  <?php
37
  }
38
 
39
  /**
40
+ * Allows the admin to restore a deleted quiz
41
+ *
42
+ * @return void
43
+ * @since 6.2.0
44
+ */
45
+ function qsm_restore_function() {
 
46
  global $wpdb;
47
+
48
+ // Checks if form was submitted.
49
+ if ( isset( $_POST['restore_quiz'] ) ) {
50
  $restore = $wpdb->update(
51
  $wpdb->prefix.'mlw_quizzes',
52
  array(
53
+ 'deleted' => 0,
54
  ),
55
  array(
56
+ 'quiz_id' => intval( $_POST['restore_quiz'] ),
57
  ),
58
  array(
59
+ '%d',
60
  ),
61
  array(
62
+ '%d',
63
  )
64
  );
65
+ if ( ! $restore ) {
66
+ ?>
67
+ <span style="color:red;"><?php esc_html_e( 'There has been an error! Please try again.', 'quiz-master-next' ); ?></span>
68
+ <?php
69
+ } else {
70
+ // Restores the quiz post type for the quiz.
71
+ $my_query = new WP_Query( array(
72
+ 'post_type' => 'quiz',
73
+ 'meta_key' => 'quiz_id',
74
+ 'meta_value' => intval( $_POST['restore_quiz'] ),
75
+ ));
76
+ if ( $my_query->have_posts() ) {
77
+ while ( $my_query->have_posts() ) {
78
+ $my_query->the_post();
79
  $my_post = array(
80
+ 'ID' => get_the_ID(),
81
+ 'post_status' => 'publish',
82
+ );
83
  wp_update_post( $my_post );
84
+ }
85
  }
86
  wp_reset_postdata();
87
+ ?>
88
+ <span style="color:red;"><?php esc_html_e( 'Quiz Has Been Restored!', 'quiz-master-next' ); ?></span>
89
+ <?php
90
  }
91
  }
92
+ $quizzes = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}mlw_quizzes WHERE deleted = 1" );
93
  ?>
94
+ <h3><?php esc_html_e( 'Choose a quiz in the drop down and then click the button to restore a deleted quiz.', 'quiz-master-next' ); ?></h3>
95
  <form action='' method="post">
96
  <select name="restore_quiz">
97
  <?php
98
+ foreach ( $quizzes as $quiz ) {
99
+ ?>
100
+ <option value="<?php echo esc_attr( $quiz->quiz_id ); ?>"><?php echo esc_html( $quiz->quiz_name ); ?></option>
101
+ <?php
102
  }
103
  ?>
104
  </select>
105
+ <button class="button"><?php esc_html_e( 'Restore Quiz', 'quiz-master-next' ); ?></button>
106
  </form>
107
  <?php
108
  }
109
 
110
  /**
111
+ * Creates the tools page that is used to make audits on the quizzes.
112
+ *
113
+ * @return void
114
+ * @since 6.2.0
115
+ */
116
+ function qsm_audit_box() {
 
117
  global $wpdb;
118
+ $table_limit = 30;
119
+ $audit_total = $wpdb->get_var( "SELECT COUNT(trail_id) FROM {$wpdb->prefix}mlw_qm_audit_trail" );
120
+
121
+ // If user has gone to the next audit page, load current page and beginning.
122
+ // Else, start at 0.
123
+ if ( isset( $_GET['audit_page'] ) ) {
124
+ $page = intval( $_GET['audit_page'] ) + 1;
125
+ $begin = $table_limit * $begin;
126
+ } else {
127
+ $page = 0;
128
+ $begin = 0;
129
  }
130
+ $left = $audit_total - ( $page * $table_limit );
 
 
 
 
 
 
131
  $audit_trails = $wpdb->get_results( $wpdb->prepare( "SELECT trail_id, action_user, action, time
132
+ FROM {$wpdb->prefix}mlw_qm_audit_trail ORDER BY trail_id DESC LIMIT %d, %d", $begin, $table_limit ) );
133
+ ?>
134
+ <p>Total actions since QSM installed: <?php echo esc_html( $audit_total ); ?></p>
135
+ <?php
136
 
137
+ // Determine which navigation to show.
138
+ if ( $page > 0 ) {
139
+ $previous = $page - 2;
140
+ ?>
141
+ <a class="button" id="prev_page" href="?page=qsm_quiz_tools&&audit_page=<?php esc_attr( $previous ); ?>">
142
+ <?php echo sprintf( esc_html__( 'Previous %s Audits', 'quiz-master-next' ), $table_limit ); ?>
143
+ </a>
144
+ <?php
145
+ if ( $left > $table_limit ) {
146
+ ?>
147
+ <a class="button" id="next_page" href="?page=qsm_quiz_tools&&audit_page=<?php esc_attr( $page ); ?>">
148
+ <?php echo sprintf( esc_html__( 'Next %s Audits', 'quiz-master-next' ), $table_limit ); ?>
149
+ </a>
150
+ <?php
151
  }
152
+ } elseif ( $page == 0 ) {
153
+ if ( $left > $table_limit ) {
154
+ ?>
155
+ <a class="button" id="next_page" href="?page=qsm_quiz_tools&&audit_page=<?php esc_attr( $page ); ?>">
156
+ <?php echo sprintf( esc_html__( 'Next %s Audits', 'quiz-master-next' ), $table_limit ); ?>
157
+ </a>
158
+ <?php
159
+ }
160
+ } elseif ( $left < $table_limit ) {
161
+ $previous = $page - 2;
162
+ ?>
163
+ <a class="button" id="prev_page" href="?page=qsm_quiz_tools&&audit_page=<?php esc_attr( $previous ); ?>">
164
+ <?php echo sprintf( esc_html__( 'Previous %s Audits', 'quiz-master-next' ), $table_limit ); ?>
165
+ </a>
166
+ <?php
167
  }
168
  ?>
169
  <table class=widefat>
170
  <thead>
171
  <tr>
172
  <th>ID</th>
173
+ <th><?php esc_html_e( 'User', 'quiz-master-next' ); ?></th>
174
+ <th><?php esc_html_e( 'Action', 'quiz-master-next' ); ?></th>
175
+ <th><?php esc_html_e( 'Time', 'quiz-master-next' ); ?></th>
176
  </tr>
177
  </thead>
178
  <tbody id="the-list">
179
+ <?php
180
+ $alternate = '';
181
+ foreach ( $audit_trails as $audit ) {
182
+ if ( $alternate ) {
183
+ $alternate = '';
184
+ } else {
185
+ $alternate = ' class="alternate"';
186
+ }
187
+ echo "<tr{$alternate}>";
188
+ echo "<td>{$audit->trail_id}</td>";
189
+ echo "<td>{$audit->action_user}</td>";
190
+ echo "<td>{$audit->action}</td>";
191
+ echo "<td>{$audit->time}</td>";
192
+ echo "</tr>";
193
+ }
194
+ ?>
195
  </tbody>
196
  </table>
197
  <?php
php/adverts-generate.php CHANGED
@@ -1,61 +1,57 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
 
 
3
 
4
  /**
5
- * Creates the advertisements that are used throughout the plugin page.
6
- *
7
- * The advertisements are randomly generated every time the page is loaded. The function also handles the CSS for this.
8
- *
9
- * @return $mlw_advert This variable is the main variable of the function and contains the advertisement content.
10
- * @since 4.4.0
11
- */
12
- function mlw_qmn_show_adverts() {
13
 
14
- $mlw_advert = "";
15
- $mlw_advert_text = "";
16
  if ( 'true' == get_option( 'mlw_advert_shows' ) ) {
17
 
18
- $mlw_random_int = rand( 0, 3 );
19
- switch ( $mlw_random_int ) {
 
 
 
 
20
  case 0:
21
- // WP Health
22
- $mlw_advert_text = 'Want to make sure your site is healthy, secure, and live? Check out our new free WordPress plugin: <a href="https://wordpress.org/plugins/my-wp-health-check/" target="_blank">WP Health</a>!';
23
  break;
24
  case 1:
25
- // Continued development 1
26
- $mlw_advert_text = "Are you finding this plugin very beneficial? Please consider checking out our premium addons which help support continued development of this plugin. Visit our <a href=\"http://quizandsurveymaster.com/addons/?utm_source=qsm-plugin-ads&utm_medium=plugin&utm_content=continued-development-1&utm_campaign=qsm_plugin\">Addon Store</a> for details!";
27
  break;
28
  case 2:
29
- // Reporting and anaylsis 1
30
- $mlw_advert_text = "Are you receiving a lot of responses to your quizzes and surveys? Consider our Reporting and Anaylsis addon which analyzes the data for you and allows you to filter the data as well as export it! <a href=\"http://quizandsurveymaster.com/downloads/results-analysis/?utm_source=qsm-plugin-ads&utm_medium=plugin&utm_content=reporting-analysis-1&utm_campaign=qsm_plugin\">Click here for more details!</a>";
31
  break;
32
  case 3:
33
  // Email marketing integrations.
34
- $mlw_advert_text = 'Want to grow your email list? Check out our addons for adding your quiz or survey takers to your email lists! <a href="http://bit.ly/2Bsw0Je" target="_blank">View our addon store</a>.';
35
  break;
36
  default:
37
- // Reporting and anaylsis 2
38
- $mlw_advert_text = "Are you receiving a lot of responses to your quizzes and surveys? Consider our Reporting and Anaylsis addon which analyzes the data for you, graphs the data, allows you to filter the data, and export the data! <a href=\"http://quizandsurveymaster.com/downloads/results-analysis/?utm_source=qsm-plugin-ads&utm_medium=plugin&utm_content=reporting-analysis-2&utm_campaign=qsm_plugin\">Click here for more details!</a>";
39
  }
40
- $mlw_advert .= "
41
- <style>
42
- div.help_decide {
43
- display: block;
44
- text-align:center;
45
- background: #fff;
46
- border: 5px solid #1DD969;
47
- color: #000;
48
- font-weight: bold;
49
- }
50
- div.help_decide p {
51
- font-size: 14px;
52
- }
53
- </style>";
54
- $mlw_advert .= "
55
- <div class=\"help_decide\">
56
- <p>$mlw_advert_text</p>
57
- </div>";
58
  }
59
- return $mlw_advert;
60
  }
61
  ?>
1
  <?php
2
+ /**
3
+ * Generates the ads in the plugin.
4
+ *
5
+ * @package QSM
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
 
12
  /**
13
+ * Creates the advertisements that are used throughout the plugin page.
14
+ *
15
+ * The advertisements are randomly generated every time the page is loaded. The function also handles the CSS for this.
16
+ *
17
+ * @since 6.2.0
18
+ */
19
+ function qsm_show_adverts() {
 
20
 
21
+ // Checks if the option for showing ads if True. Will be false if the No Ads addon is installed.
 
22
  if ( 'true' == get_option( 'mlw_advert_shows' ) ) {
23
 
24
+ global $mlwQuizMasterNext;
25
+ wp_enqueue_style( 'qsm_admin_style', plugins_url( '../css/qsm-admin.css', __FILE__ ), array(), $mlwQuizMasterNext->version );
26
+
27
+ $ad_text = '';
28
+ $rand_int = rand( 0, 3 );
29
+ switch ( $rand_int ) {
30
  case 0:
31
+ // WP Health.
32
+ $ad_text = 'Want to make sure your site is healthy, secure, and live? Check out our new free WordPress plugin: <a href="https://wordpress.org/plugins/my-wp-health-check/" target="_blank">WP Health</a>!';
33
  break;
34
  case 1:
35
+ // Continued development 1.
36
+ $ad_text = 'Are you finding this plugin very beneficial? Please consider checking out our premium addons which help support continued development of this plugin. Visit our <a href="http://quizandsurveymaster.com/addons/?utm_source=qsm-plugin-ads&utm_medium=plugin&utm_content=continued-development-1&utm_campaign=qsm_plugin">Addon Store</a> for details!';
37
  break;
38
  case 2:
39
+ // Reporting and anaylsis 1.
40
+ $ad_text = 'Are you receiving a lot of responses to your quizzes and surveys? Consider our Reporting and Anaylsis addon which analyzes the data for you and allows you to filter the data as well as export it! <a href="http://quizandsurveymaster.com/downloads/results-analysis/?utm_source=qsm-plugin-ads&utm_medium=plugin&utm_content=reporting-analysis-1&utm_campaign=qsm_plugin">Click here for more details!</a>';
41
  break;
42
  case 3:
43
  // Email marketing integrations.
44
+ $ad_text = 'Want to grow your email list? Check out our addons for adding your quiz or survey takers to your email lists! <a href="http://bit.ly/2Bsw0Je" target="_blank">View our addon store</a>.';
45
  break;
46
  default:
47
+ // Reporting and anaylsis 2.
48
+ $ad_text = 'Are you receiving a lot of responses to your quizzes and surveys? Consider our Reporting and Anaylsis addon which analyzes the data for you, graphs the data, allows you to filter the data, and export the data! <a href="http://quizandsurveymaster.com/downloads/results-analysis/?utm_source=qsm-plugin-ads&utm_medium=plugin&utm_content=reporting-analysis-2&utm_campaign=qsm_plugin">Click here for more details!</a>';
49
  }
50
+ ?>
51
+ <div class="help-decide">
52
+ <p><?php echo $ad_text; ?></p>
53
+ </div>
54
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
 
56
  }
57
  ?>
php/classes/class-qmn-quiz-manager.php CHANGED
@@ -745,10 +745,10 @@ class QMNQuizManager {
745
  }
746
 
747
  // Gathers contact information.
748
- $qmn_array_for_variables['user_name'] = 'None';
749
  $qmn_array_for_variables['user_business'] = 'None';
750
- $qmn_array_for_variables['user_email'] = 'None';
751
- $qmn_array_for_variables['user_phone'] = 'None';
752
  $contact_responses = QSM_Contact_Manager::process_fields( $qmn_quiz_options );
753
  foreach ( $contact_responses as $field ) {
754
  if ( isset( $field['use'] ) ) {
@@ -779,8 +779,12 @@ class QMNQuizManager {
779
  $result_display = apply_filters('qmn_after_check_answers', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
780
  $qmn_array_for_variables['comments'] = $this->check_comment_section($qmn_quiz_options, $qmn_array_for_variables);
781
  $result_display = apply_filters('qmn_after_check_comments', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
782
- $result_display .= $this->display_results_text($qmn_quiz_options, $qmn_array_for_variables);
 
 
 
783
  $result_display = apply_filters('qmn_after_results_text', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
 
784
  $result_display .= $this->display_social($qmn_quiz_options, $qmn_array_for_variables);
785
  $result_display = apply_filters('qmn_after_social_media', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
786
 
@@ -848,14 +852,18 @@ class QMNQuizManager {
848
  // Hook is fired after the responses are submitted. Passes responses, result ID, quiz settings, and response data.
849
  do_action( 'qsm_quiz_submitted', $results_array, $results_id, $qmn_quiz_options, $qmn_array_for_variables );
850
 
851
- // Sends user email.
852
- $this->send_user_email( $qmn_quiz_options, $qmn_array_for_variables );
853
- $result_display = apply_filters( 'qmn_after_send_user_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
854
 
855
- // Sends admin email.
856
- $this->send_admin_email($qmn_quiz_options, $qmn_array_for_variables);
 
 
 
 
 
857
  $result_display = apply_filters( 'qmn_after_send_admin_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
858
-
859
  // Last time to filter the HTML results page.
860
  $result_display = apply_filters( 'qmn_end_results', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
861
 
@@ -865,54 +873,10 @@ class QMNQuizManager {
865
  $result_display .= 'Thank you.';
866
  }
867
 
868
- // Checks to see if we need to set up a redirect.
869
- $redirect = false;
870
- $redirect_url = '';
871
- if ( is_serialized( $qmn_quiz_options->message_after ) && is_array( @unserialize( $qmn_quiz_options->message_after ) ) ) {
872
- $mlw_message_after_array = @unserialize( $qmn_quiz_options->message_after );
873
-
874
- // Cycles through landing pages.
875
- foreach( $mlw_message_after_array as $mlw_each ) {
876
- // Checks to see if not default.
877
- if ( $mlw_each[0] != 0 || $mlw_each[1] != 0 ) {
878
- // Checks to see if points fall in correct range.
879
- if ($qmn_quiz_options->system == 1 && $qmn_array_for_variables['total_points'] >= $mlw_each[0] && $qmn_array_for_variables['total_points'] <= $mlw_each[1])
880
- {
881
- if (esc_url($mlw_each["redirect_url"]) != '')
882
- {
883
- $redirect = true;
884
- $redirect_url = esc_url( $mlw_each["redirect_url"] );
885
- }
886
- break;
887
- }
888
- //Check to see if score fall in correct range
889
- if ($qmn_quiz_options->system == 0 && $qmn_array_for_variables['total_score'] >= $mlw_each[0] && $qmn_array_for_variables['total_score'] <= $mlw_each[1])
890
- {
891
- if (esc_url($mlw_each["redirect_url"]) != '')
892
- {
893
- $redirect = true;
894
- $redirect_url = esc_url( $mlw_each["redirect_url"] );
895
- }
896
- break;
897
- }
898
- }
899
- else
900
- {
901
- if (esc_url($mlw_each["redirect_url"]) != '')
902
- {
903
- $redirect = true;
904
- $redirect_url = esc_url( $mlw_each["redirect_url"] );
905
- }
906
- break;
907
- }
908
- }
909
- }
910
-
911
  // Prepares data to be sent back to front-end.
912
  $return_array = array(
913
  'display' => $result_display,
914
- 'redirect' => $redirect,
915
- 'redirect_url' => $redirect_url,
916
  );
917
 
918
  return $return_array;
@@ -1122,107 +1086,54 @@ class QMNQuizManager {
1122
 
1123
 
1124
  /**
1125
- * Displays Results Text
1126
- *
1127
- * Prepares and display text for the results page
1128
- *
1129
- * @since 4.0.0
1130
- * @param array $qmn_quiz_options The database row of the quiz
1131
- * @param array $qmn_array_for_variables The array of results for the quiz
1132
- * @return string The contents for the results text
1133
- */
1134
- public function display_results_text($qmn_quiz_options, $qmn_array_for_variables)
1135
- {
1136
- $results_text_display = '';
1137
- if (is_serialized($qmn_quiz_options->message_after) && is_array(@unserialize($qmn_quiz_options->message_after)))
1138
- {
1139
- $mlw_message_after_array = @unserialize($qmn_quiz_options->message_after);
1140
- //Cycle through landing pages
1141
- foreach($mlw_message_after_array as $mlw_each)
1142
- {
1143
- //Check to see if default
1144
- if ($mlw_each[0] == 0 && $mlw_each[1] == 0)
1145
- {
1146
- $mlw_message_after = htmlspecialchars_decode($mlw_each[2], ENT_QUOTES);
1147
- $mlw_message_after = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message_after, $qmn_array_for_variables);
1148
- $mlw_message_after = str_replace( "\n" , "<br>", $mlw_message_after);
1149
- $results_text_display .= $mlw_message_after;
1150
- break;
1151
- }
1152
- else
1153
- {
1154
- //Check to see if points fall in correct range
1155
- if ($qmn_quiz_options->system == 1 && $qmn_array_for_variables['total_points'] >= $mlw_each[0] && $qmn_array_for_variables['total_points'] <= $mlw_each[1])
1156
- {
1157
- $mlw_message_after = htmlspecialchars_decode($mlw_each[2], ENT_QUOTES);
1158
- $mlw_message_after = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message_after, $qmn_array_for_variables);
1159
- $mlw_message_after = str_replace( "\n" , "<br>", $mlw_message_after);
1160
- $results_text_display .= $mlw_message_after;
1161
- break;
1162
- }
1163
- //Check to see if score fall in correct range
1164
- if ($qmn_quiz_options->system == 0 && $qmn_array_for_variables['total_score'] >= $mlw_each[0] && $qmn_array_for_variables['total_score'] <= $mlw_each[1])
1165
- {
1166
- $mlw_message_after = htmlspecialchars_decode($mlw_each[2], ENT_QUOTES);
1167
- $mlw_message_after = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message_after, $qmn_array_for_variables);
1168
- $mlw_message_after = str_replace( "\n" , "<br>", $mlw_message_after);
1169
- $results_text_display .= $mlw_message_after;
1170
- break;
1171
- }
1172
- }
1173
- }
1174
- }
1175
- else
1176
- {
1177
- //Prepare the after quiz message
1178
- $mlw_message_after = htmlspecialchars_decode($qmn_quiz_options->message_after, ENT_QUOTES);
1179
- $mlw_message_after = apply_filters( 'mlw_qmn_template_variable_results_page', $mlw_message_after, $qmn_array_for_variables);
1180
- $mlw_message_after = str_replace( "\n" , "<br>", $mlw_message_after);
1181
- $results_text_display .= $mlw_message_after;
1182
- }
1183
- return do_shortcode( $results_text_display );
1184
  }
1185
 
1186
  /**
1187
- * Display Social Media Buttons
1188
- *
1189
- * Prepares and displays social media buttons for sharing results
1190
- *
1191
- * @since 4.0.0
1192
- * @param array $qmn_quiz_options The database row of the quiz
1193
- * @param array $qmn_array_for_variables The array of results for the quiz
1194
- * @return string The content of the social media button section
1195
- */
1196
- public function display_social($qmn_quiz_options, $qmn_array_for_variables)
1197
- {
1198
  $social_display = '';
1199
- if ($qmn_quiz_options->social_media == 1)
1200
- {
1201
  $settings = (array) get_option( 'qmn-settings' );
1202
  $facebook_app_id = '483815031724529';
1203
- if (isset($settings['facebook_app_id']))
1204
- {
1205
  $facebook_app_id = esc_js( $settings['facebook_app_id'] );
1206
  }
1207
 
1208
- //Load Social Media Text
1209
  $qmn_social_media_text = "";
1210
  if ( is_serialized( $qmn_quiz_options->social_media_text ) && is_array( @unserialize( $qmn_quiz_options->social_media_text ) ) ) {
1211
  $qmn_social_media_text = @unserialize($qmn_quiz_options->social_media_text);
1212
  } else {
1213
  $qmn_social_media_text = array(
1214
- 'twitter' => $qmn_quiz_options->social_media_text,
1215
- 'facebook' => $qmn_quiz_options->social_media_text
1216
- );
1217
  }
1218
- $qmn_social_media_text["twitter"] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text["twitter"], $qmn_array_for_variables);
1219
  $qmn_social_media_text["facebook"] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text["facebook"], $qmn_array_for_variables);
1220
  $social_display .= "<br />
1221
  <a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('facebook', '".esc_js($qmn_social_media_text["facebook"])."', '".esc_js($qmn_quiz_options->quiz_name)."', '$facebook_app_id');\">Facebook</a>
1222
  <a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('twitter', '".esc_js($qmn_social_media_text["twitter"])."', '".esc_js($qmn_quiz_options->quiz_name)."');\">Twitter</a>
1223
  <br />";
1224
  }
1225
- return apply_filters('qmn_returned_social_buttons', $social_display, $qmn_quiz_options, $qmn_array_for_variables);
1226
  }
1227
 
1228
  /**
@@ -1230,6 +1141,7 @@ class QMNQuizManager {
1230
  *
1231
  * Prepares the email to the user and then sends the email
1232
  *
 
1233
  * @since 4.0.0
1234
  * @param array $qmn_quiz_options The database row of the quiz
1235
  * @param array $qmn_array_for_variables The array of results for the quiz
@@ -1338,6 +1250,7 @@ class QMNQuizManager {
1338
  *
1339
  * Prepares the email to the admin and then sends the email
1340
  *
 
1341
  * @since 4.0.0
1342
  * @param array $qmn_quiz_options The database row of the quiz
1343
  * @param arrar $qmn_array_for_variables The array of results for the quiz
745
  }
746
 
747
  // Gathers contact information.
748
+ $qmn_array_for_variables['user_name'] = 'None';
749
  $qmn_array_for_variables['user_business'] = 'None';
750
+ $qmn_array_for_variables['user_email'] = 'None';
751
+ $qmn_array_for_variables['user_phone'] = 'None';
752
  $contact_responses = QSM_Contact_Manager::process_fields( $qmn_quiz_options );
753
  foreach ( $contact_responses as $field ) {
754
  if ( isset( $field['use'] ) ) {
779
  $result_display = apply_filters('qmn_after_check_answers', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
780
  $qmn_array_for_variables['comments'] = $this->check_comment_section($qmn_quiz_options, $qmn_array_for_variables);
781
  $result_display = apply_filters('qmn_after_check_comments', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
782
+
783
+ // Determines redirect/results page.
784
+ $results_pages = $this->display_results_text( $qmn_quiz_options, $qmn_array_for_variables );
785
+ $result_display .= $results_pages['display'];
786
  $result_display = apply_filters('qmn_after_results_text', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
787
+
788
  $result_display .= $this->display_social($qmn_quiz_options, $qmn_array_for_variables);
789
  $result_display = apply_filters('qmn_after_social_media', $result_display, $qmn_quiz_options, $qmn_array_for_variables);
790
 
852
  // Hook is fired after the responses are submitted. Passes responses, result ID, quiz settings, and response data.
853
  do_action( 'qsm_quiz_submitted', $results_array, $results_id, $qmn_quiz_options, $qmn_array_for_variables );
854
 
855
+ // Sends the emails.
856
+ QSM_Emails::send_emails( $qmn_array_for_variables );
 
857
 
858
+ /**
859
+ * Filters for filtering the results text after emails are sent.
860
+ *
861
+ * @deprecated 6.2.0 There's no reason to use these over the actions
862
+ * in the QSM_Results_Pages class or the other filters in this function.
863
+ */
864
+ $result_display = apply_filters( 'qmn_after_send_user_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
865
  $result_display = apply_filters( 'qmn_after_send_admin_email', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
866
+
867
  // Last time to filter the HTML results page.
868
  $result_display = apply_filters( 'qmn_end_results', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
869
 
873
  $result_display .= 'Thank you.';
874
  }
875
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876
  // Prepares data to be sent back to front-end.
877
  $return_array = array(
878
  'display' => $result_display,
879
+ 'redirect' => $results_pages['redirect'],
 
880
  );
881
 
882
  return $return_array;
1086
 
1087
 
1088
  /**
1089
+ * Displays Results Text
1090
+ *
1091
+ * @since 4.0.0
1092
+ * @deprecated 6.1.0 Use the newer results page class instead.
1093
+ * @param array $options The quiz settings.
1094
+ * @param array $response_data The array of results for the quiz.
1095
+ * @return string The contents for the results text
1096
+ */
1097
+ public function display_results_text( $options, $response_data ) {
1098
+ return QSM_Results_Pages::generate_pages( $response_data );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1099
  }
1100
 
1101
  /**
1102
+ * Displays social media buttons
1103
+ *
1104
+ * @deprecated 6.1.0 Use the social media template variables instead.
1105
+ * @since 4.0.0
1106
+ * @param array $qmn_quiz_options The database row of the quiz.
1107
+ * @param array $qmn_array_for_variables The array of results for the quiz.
1108
+ * @return string The content of the social media button section
1109
+ */
1110
+ public function display_social( $qmn_quiz_options, $qmn_array_for_variables ) {
 
 
1111
  $social_display = '';
1112
+ if ( $qmn_quiz_options->social_media == 1 ) {
 
1113
  $settings = (array) get_option( 'qmn-settings' );
1114
  $facebook_app_id = '483815031724529';
1115
+ if ( isset( $settings['facebook_app_id'] ) ) {
 
1116
  $facebook_app_id = esc_js( $settings['facebook_app_id'] );
1117
  }
1118
 
1119
+ // Loads Social Media Text.
1120
  $qmn_social_media_text = "";
1121
  if ( is_serialized( $qmn_quiz_options->social_media_text ) && is_array( @unserialize( $qmn_quiz_options->social_media_text ) ) ) {
1122
  $qmn_social_media_text = @unserialize($qmn_quiz_options->social_media_text);
1123
  } else {
1124
  $qmn_social_media_text = array(
1125
+ 'twitter' => $qmn_quiz_options->social_media_text,
1126
+ 'facebook' => $qmn_quiz_options->social_media_text,
1127
+ );
1128
  }
1129
+ $qmn_social_media_text["twitter"] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text["twitter"], $qmn_array_for_variables);
1130
  $qmn_social_media_text["facebook"] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text["facebook"], $qmn_array_for_variables);
1131
  $social_display .= "<br />
1132
  <a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('facebook', '".esc_js($qmn_social_media_text["facebook"])."', '".esc_js($qmn_quiz_options->quiz_name)."', '$facebook_app_id');\">Facebook</a>
1133
  <a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('twitter', '".esc_js($qmn_social_media_text["twitter"])."', '".esc_js($qmn_quiz_options->quiz_name)."');\">Twitter</a>
1134
  <br />";
1135
  }
1136
+ return apply_filters( 'qmn_returned_social_buttons', $social_display, $qmn_quiz_options, $qmn_array_for_variables );
1137
  }
1138
 
1139
  /**
1141
  *
1142
  * Prepares the email to the user and then sends the email
1143
  *
1144
+ * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
1145
  * @since 4.0.0
1146
  * @param array $qmn_quiz_options The database row of the quiz
1147
  * @param array $qmn_array_for_variables The array of results for the quiz
1250
  *
1251
  * Prepares the email to the admin and then sends the email
1252
  *
1253
+ * @deprecated 6.2.0 Use the newer QSM_Emails class instead.
1254
  * @since 4.0.0
1255
  * @param array $qmn_quiz_options The database row of the quiz
1256
  * @param arrar $qmn_array_for_variables The array of results for the quiz
php/classes/class-qsm-emails.php ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Handles relevant functions for emails
4
+ *
5
+ * @package QSM
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ /**
13
+ * This class contains functions for loading, saving, and send quiz emails.
14
+ *
15
+ * @since 6.2.0
16
+ */
17
+ class QSM_Emails {
18
+
19
+ /**
20
+ * Sends the emails for the quiz.
21
+ *
22
+ * @since 6.2.0
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;
30
+ }
31
+
32
+ add_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
33
+
34
+ // Cycles through each possible email.
35
+ foreach ( $emails as $email ) {
36
+
37
+ // Checks if any conditions are present. Else, send it always.
38
+ if ( ! empty( $email['conditions'] ) ) {
39
+ /**
40
+ * Since we have many conditions to test, we set this to true first.
41
+ * Then, we test each condition to see if it fails.
42
+ * If one condition fails, the value will be set to false.
43
+ * If all conditions pass, this will still be true and the email will
44
+ * be sent.
45
+ */
46
+ $show = true;
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
+
52
+ // First, determine which value we need to test.
53
+ switch ( $condition['criteria'] ) {
54
+ case 'score':
55
+ $test = $response_data['total_score'];
56
+ break;
57
+
58
+ case 'points':
59
+ $test = $response_data['total_points'];
60
+ break;
61
+
62
+ default:
63
+ $test = 0;
64
+ break;
65
+ }
66
+
67
+ // Then, determine how to test the vaue.
68
+ switch ( $condition['operator'] ) {
69
+ case 'greater-equal':
70
+ if ( $test < $value ) {
71
+ $show = false;
72
+ }
73
+ break;
74
+
75
+ case 'greater':
76
+ if ( $test <= $value ) {
77
+ $show = false;
78
+ }
79
+ break;
80
+
81
+ case 'less-equal':
82
+ if ( $test > $value ) {
83
+ $show = false;
84
+ }
85
+ break;
86
+
87
+ case 'less':
88
+ if ( $test >= $value ) {
89
+ $show = false;
90
+ }
91
+ break;
92
+
93
+ case 'not-equal':
94
+ if ( $test == $value ) {
95
+ $show = false;
96
+ }
97
+ break;
98
+
99
+ case 'equal':
100
+ default:
101
+ if ( $test != $value ) {
102
+ $show = false;
103
+ }
104
+ break;
105
+ }
106
+
107
+ /**
108
+ * Added custom criterias/operators to the email?
109
+ * Use this filter to check if the condition passed.
110
+ * If it fails your conditions, return false to prevent the
111
+ * email from sending.
112
+ * If it passes your condition or is not your custom criterias
113
+ * or operators, then return the value as-is.
114
+ * DO NOT RETURN TRUE IF IT PASSES THE CONDITION!!!
115
+ * The value may have been set to false when failing a previous condition.
116
+ */
117
+ $show = apply_filters( 'qsm_email_condition_check', $show, $condition, $response_data );
118
+ }
119
+
120
+ if ( $show ) {
121
+ QSM_Emails::send_results_email( $response_data, $email['to'], $email['subject'], $email['content'], $email['replyTo'] );
122
+ }
123
+ } else {
124
+ QSM_Emails::send_results_email( $response_data, $email['to'], $email['subject'], $email['content'], $email['replyTo'] );
125
+ }
126
+ }
127
+
128
+ remove_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
129
+ }
130
+
131
+ /**
132
+ * Sends the results email.
133
+ *
134
+ * @since 6.2.0
135
+ * @param array $response_data The data for the user's submission.
136
+ * @param string $to The email(s) to send to. Can be separated with commas.
137
+ * @param string $subject The subject of the email.
138
+ * @param string $content The body of the email.
139
+ * @param bool $reply_to True if set user email as Reply To header.
140
+ */
141
+ public static function send_results_email( $response_data, $to, $subject, $content, $reply_to ) {
142
+
143
+ global $mlwQuizMasterNext;
144
+
145
+ // Sets up our to email addresses.
146
+ $user_email = sanitize_email( $response_data['user_email'] );
147
+ $count = 0;
148
+ if ( is_email( $user_email ) ) {
149
+ $to = str_replace( '%USER_EMAIL%', $response_data['user_email'], $to, $count );
150
+ } else {
151
+ $to = str_replace( '%USER_EMAIL%', '', $to );
152
+ }
153
+ $to_array = explode( ',', $to );
154
+
155
+ // Prepares our subject.
156
+ $subject = apply_filters( 'mlw_qmn_template_variable_results_page', $subject, $response_data );
157
+
158
+ // Prepares our content.
159
+ $content = htmlspecialchars_decode( $content, ENT_QUOTES );
160
+ $content = apply_filters( 'mlw_qmn_template_variable_results_page', $content, $response_data );
161
+ $content = str_replace( "\n", '<br>', $content );
162
+ $content = str_replace( '<br/>', '<br>', $content );
163
+ $content = str_replace( '<br />', '<br>', $content );
164
+
165
+ // Prepares our from name and email.
166
+ $settings = (array) get_option( 'qmn-settings' );
167
+ $from_email = get_option( 'admin_email', 'a@example.com' );
168
+ $from_name = get_bloginfo( 'name' );
169
+ if ( ! isset( $settings['from_email'] ) && ! isset( $settings['from_name'] ) ) {
170
+ $options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
171
+ $from_array = maybe_unserialize( $options->email_from_text );
172
+ if ( isset( $from_array['from_email'] ) ) {
173
+ $from_email = $from_array['from_email'];
174
+ $from_name = $from_array['from_name'];
175
+
176
+ // Updates option with this quiz's from values.
177
+ $settings['from_email'] = $from_email;
178
+ $settings['from_name'] = $from_name;
179
+ update_option( 'qmn-settings', $settings );
180
+ }
181
+ } else {
182
+ if ( isset( $settings['from_email'] ) ) {
183
+ $from_email = $settings['from_email'];
184
+ }
185
+ if ( isset( $settings['from_name'] ) ) {
186
+ $from_name = $settings['from_name'];
187
+ }
188
+ }
189
+
190
+ // Prepares our headers.
191
+ $headers = array(
192
+ 'From: ' . $from_name . ' <' . $from_email . '>',
193
+ );
194
+ if ( is_email( $user_email ) && true === $reply_to ) {
195
+ $name = sanitize_text_field( $response_data['user_name'] );
196
+ $headers[] = 'Reply-To: ' . $name . ' <' . $user_email . '>';
197
+ }
198
+
199
+ // Prepares our attachments. If %USER_EMAIL% was in the $to, then use the user email attachment filter.
200
+ $attachments = array();
201
+ if ( 0 < intval( $count ) ) {
202
+ $attachments = apply_filters( 'qsm_user_email_attachments', $attachments, $response_data );
203
+ } else {
204
+ $attachments = apply_filters( 'qsm_admin_email_attachments', $attachments, $response_data );
205
+ }
206
+
207
+ // Cycle through each to email address and send the email.
208
+ foreach ( $to_array as $to_email ) {
209
+ if ( is_email( $to_email ) ) {
210
+ wp_mail( $to_email, $subject, $content, $headers, $attachments );
211
+ }
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Loads the emails for a single quiz.
217
+ *
218
+ * @since 6.2.0
219
+ * @param int $quiz_id The ID for the quiz.
220
+ * @return bool|array The array of emails or false.
221
+ */
222
+ public static function load_emails( $quiz_id ) {
223
+ $emails = array();
224
+ $quiz_id = intval( $quiz_id );
225
+
226
+ // If the parameter supplied turns to 0 after intval, returns false.
227
+ if ( 0 === $quiz_id ) {
228
+ return false;
229
+ }
230
+
231
+ global $wpdb;
232
+ $data = $wpdb->get_var( $wpdb->prepare( "SELECT user_email_template FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ) );
233
+
234
+ // Checks if the emails is an array.
235
+ if ( is_serialized( $data ) && is_array( maybe_unserialize( $data ) ) ) {
236
+ $data = maybe_unserialize( $data );
237
+
238
+ // Checks if the emails array is not the newer version.
239
+ if ( ! empty( $data ) && ! isset( $data[0]['conditions'] ) ) {
240
+ $emails = QSM_Emails::convert_to_new_system( $quiz_id );
241
+ } else {
242
+ $emails = $data;
243
+ }
244
+ } else {
245
+ $emails = QSM_Emails::convert_to_new_system( $quiz_id );
246
+ }
247
+
248
+ return $emails;
249
+ }
250
+
251
+ /**
252
+ * Loads and converts emails from the old system to new system
253
+ *
254
+ * @since 6.2.0
255
+ * @param int $quiz_id The ID for the quiz.
256
+ * @return array The combined newer versions of the emails.
257
+ */
258
+ public static function convert_to_new_system( $quiz_id ) {
259
+ $emails = array();
260
+ $quiz_id = intval( $quiz_id );
261
+
262
+ // If the parameter supplied turns to 0 after intval, returns empty array.
263
+ if ( 0 === $quiz_id ) {
264
+ return $emails;
265
+ }
266
+
267
+ /**
268
+ * Loads the old user and admin emails. Checks if they are enabled and converts them.
269
+ */
270
+ global $wpdb;
271
+ global $mlwQuizMasterNext;
272
+ $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 );
273
+ $system = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'system', 0 );
274
+ if ( 0 === intval( $data['send_user_email'] ) ) {
275
+ $emails = array_merge( $emails, QSM_Emails::convert_emails( $system, $data['user_email_template'] ) );
276
+ }
277
+ if ( 0 === intval( $data['send_admin_email'] ) ) {
278
+ $from_email_array = maybe_unserialize( $data['email_from_text'] );
279
+ if ( ! is_array( $from_email_array ) || ! isset( $from_email_array['reply_to'] ) ) {
280
+ $from_email_array = array(
281
+ 'reply_to' => 1,
282
+ );
283
+ }
284
+ $emails = array_merge( $emails, QSM_Emails::convert_emails( $system, $data['admin_email_template'], $data['admin_email'], $from_email_array['reply_to'] ) );
285
+ }
286
+
287
+ // Updates the database with new array to prevent running this step next time.
288
+ $wpdb->update(
289
+ $wpdb->prefix . 'mlw_quizzes',
290
+ array( 'user_email_template' => serialize( $emails ) ),
291
+ array( 'quiz_id' => $quiz_id ),
292
+ array( '%s' ),
293
+ array( '%d' )
294
+ );
295
+
296
+ return $emails;
297
+ }
298
+
299
+ /**
300
+ * Converts emails to new system.
301
+ *
302
+ * @since 6.2.0
303
+ * @param int $system The grading system of the quiz.
304
+ * @param array $emails The emails to convert.
305
+ * @param string $admin_emails The emails to send admin emails to, separated by comma.
306
+ * @param int $reply_to Whether to add user email as Reply-To header (0 is enabled).
307
+ * @return array The emails that have been converted.
308
+ */
309
+ public static function convert_emails( $system, $emails, $admin_emails = false, $reply_to = false ) {
310
+ $new_emails = array();
311
+ $emails = maybe_unserialize( $emails );
312
+
313
+ // Checks if emails is an array to cycle through.
314
+ if ( is_array( $emails ) ) {
315
+
316
+ // Cycles through the emails.
317
+ foreach ( $emails as $email ) {
318
+
319
+ // Because I didn't appreciate consistency as a young developer...
320
+ if ( isset( $email['subject'] ) ) {
321
+ $subject = $email['subject'];
322
+ $message = $email['message'];
323
+ $begin = $email['begin_score'];
324
+ $end = $email['end_score'];
325
+ } else {
326
+ $subject = $email[3];
327
+ $message = $email[2];
328
+ $begin = $email[0];
329
+ $end = $email[1];
330
+ }
331
+
332
+ // Sets up our basic email.
333
+ $new_email = array(
334
+ 'conditions' => array(),
335
+ 'subject' => $subject,
336
+ 'content' => $message,
337
+ 'replyTo' => false,
338
+ );
339
+
340
+ // Prepares the to email.
341
+ if ( false === $admin_emails ) {
342
+ $new_email['to'] = '%USER_EMAIL%';
343
+ } elseif ( is_string( $admin_emails ) ) {
344
+ $new_email['to'] = $admin_emails;
345
+ } else {
346
+ $new_email['to'] = get_option( 'admin_email ', 'test@example.com' );
347
+ }
348
+
349
+ // Sets reply to option to True if was enabled previously.
350
+ if ( false !== $reply_to ) {
351
+ if ( 0 === intval( $reply_to ) ) {
352
+ $new_email['replyTo'] = true;
353
+ }
354
+ }
355
+
356
+ // Checks to see if the email is not the older version's default page.
357
+ if ( 0 !== intval( $begin ) || 0 !== intval( $end ) ) {
358
+
359
+ // Checks if the system is points.
360
+ if ( 1 === intval( $system ) ) {
361
+ $new_email['conditions'][] = array(
362
+ 'criteria' => 'points',
363
+ 'operator' => 'greater-equal',
364
+ 'value' => $begin,
365
+ );
366
+ $new_email['conditions'][] = array(
367
+ 'criteria' => 'points',
368
+ 'operator' => 'less-equal',
369
+ 'value' => $end,
370
+ );
371
+ } else {
372
+ $new_email['conditions'][] = array(
373
+ 'criteria' => 'score',
374
+ 'operator' => 'greater-equal',
375
+ 'value' => $begin,
376
+ );
377
+ $new_email['conditions'][] = array(
378
+ 'criteria' => 'score',
379
+ 'operator' => 'less-equal',
380
+ 'value' => $end,
381
+ );
382
+ }
383
+ }
384
+
385
+ $new_emails[] = $new_email;
386
+ }
387
+ } else {
388
+ $new_emails[] = array(
389
+ 'conditions' => array(),
390
+ 'content' => $emails,
391
+ 'subject' => 'Quiz results for %QUIZ_NAME%',
392
+ 'replyTo' => false,
393
+ );
394
+
395
+ // Prepares the to email.
396
+ if ( false === $admin_emails ) {
397
+ $new_emails[0]['to'] = '%USER_EMAIL%';
398
+ } elseif ( is_string( $admin_emails ) ) {
399
+ $new_emails[0]['to'] = $admin_emails;
400
+ } else {
401
+ $new_emails[0]['to'] = get_option( 'admin_email ', 'test@example.com' );
402
+ }
403
+ }
404
+ return $new_emails;
405
+ }
406
+
407
+ /**
408
+ * Saves the emails for a quiz.
409
+ *
410
+ * @since 6.2.0
411
+ * @param int $quiz_id The ID for the quiz.
412
+ * @param array $emails The emails to be saved.
413
+ * @return bool True or false depending on success.
414
+ */
415
+ public static function save_emails( $quiz_id, $emails ) {
416
+ if ( ! is_array( $emails ) ) {
417
+ return false;
418
+ }
419
+
420
+ $quiz_id = intval( $quiz_id );
421
+ if ( 0 === $quiz_id ) {
422
+ return false;
423
+ }
424
+
425
+ // Sanitizes data in emails.
426
+ $total = count( $emails );
427
+ for ( $i = 0; $i < $total; $i++ ) {
428
+ $emails[ $i ]['to'] = sanitize_text_field( $emails[ $i ]['to'] );
429
+ $emails[ $i ]['subject'] = sanitize_text_field( $emails[ $i ]['subject'] );
430
+
431
+ /**
432
+ * The jQuery AJAX function won't send the conditions key
433
+ * if it's empty. So, check if it's set. If set, sanitize
434
+ * data. If not set, set to empty array.
435
+ */
436
+ if ( isset( $emails[ $i ]['conditions'] ) ) {
437
+ // Sanitizes the conditions.
438
+ $total_conditions = count( $emails[ $i ]['conditions'] );
439
+ for ( $j = 0; $j < $total_conditions; $j++ ) {
440
+ $emails[ $i ]['conditions'][ $j ]['value'] = sanitize_text_field( $emails[ $i ]['conditions'][ $j ]['value'] );
441
+ }
442
+ } else {
443
+ $emails[ $i ]['conditions'] = array();
444
+ }
445
+
446
+ if ( 'true' === $emails[ $i ]['replyTo'] || true === $emails[ $i ]['replyTo'] ) {
447
+ $emails[ $i ]['replyTo'] = true;
448
+ } else {
449
+ $emails[ $i ]['replyTo'] = false;
450
+ }
451
+ }
452
+
453
+ global $wpdb;
454
+ $results = $wpdb->update(
455
+ $wpdb->prefix . 'mlw_quizzes',
456
+ array( 'user_email_template' => serialize( $emails ) ),
457
+ array( 'quiz_id' => $quiz_id ),
458
+ array( '%s' ),
459
+ array( '%d' )
460
+ );
461
+ if ( false !== $results ) {
462
+ return true;
463
+ } else {
464
+ return false;
465
+ }
466
+ }
467
+ }
468
+ ?>
php/classes/class-qsm-install.php CHANGED
@@ -1280,9 +1280,7 @@ class QSM_Install {
1280
 
1281
  // Update 5.0.0
1282
  $settings = (array) get_option( 'qmn-settings', array() );
1283
- if ( isset( $settings['results_details_template'] ) ) {
1284
- $settings['results_details_template'] .= "<p>%CONTACT_ALL%</p>";
1285
- } else {
1286
  $settings['results_details_template'] = "<h2>Quiz Results for %QUIZ_NAME%</h2>
1287
  <p>%CONTACT_ALL%</p>
1288
  <p>Name Provided: %USER_NAME%</p>
@@ -1294,16 +1292,11 @@ class QSM_Install {
1294
  <p>The user took %TIMER% to complete quiz.</p>
1295
  <p>Comments entered were: %COMMENT_SECTION%</p>
1296
  <p>The answers were as follows:</p>
1297
- %QUESTIONS_ANSWERS%";
 
1298
  }
1299
- update_option( 'qmn-settings' , $settings );
1300
-
1301
-
1302
  update_option('mlw_quiz_master_version' , $data);
1303
- if( ! isset( $_GET['activate-multi'] ) ) {
1304
- wp_safe_redirect( admin_url( 'index.php?page=qsm_about' ) );
1305
- exit;
1306
- }
1307
  }
1308
  if ( ! get_option('mlw_advert_shows') ) {
1309
  add_option( 'mlw_advert_shows' , 'true' );
@@ -1331,7 +1324,7 @@ class QSM_Install {
1331
  if ( $file == QSM_PLUGIN_BASENAME ) {
1332
  $row_meta = array(
1333
  'docs' => '<a href="' . esc_url( 'https://docs.quizandsurveymaster.com/' ) . '" title="' . esc_attr( __( 'View Documentation', 'quiz-master-next' ) ) . '">' . __( 'Documentation', 'quiz-master-next' ) . '</a>',
1334
- 'support' => '<a href="' . admin_url( 'admin.php?page=mlw_quiz_help' ) . '" title="' . esc_attr( __( 'Create Support Ticket', 'quiz-master-next' ) ) . '">' . __( 'Support', 'quiz-master-next' ) . '</a>',
1335
  );
1336
  return array_merge( $links, $row_meta );
1337
  }
1280
 
1281
  // Update 5.0.0
1282
  $settings = (array) get_option( 'qmn-settings', array() );
1283
+ if ( ! isset( $settings['results_details_template'] ) ) {
 
 
1284
  $settings['results_details_template'] = "<h2>Quiz Results for %QUIZ_NAME%</h2>
1285
  <p>%CONTACT_ALL%</p>
1286
  <p>Name Provided: %USER_NAME%</p>
1292
  <p>The user took %TIMER% to complete quiz.</p>
1293
  <p>Comments entered were: %COMMENT_SECTION%</p>
1294
  <p>The answers were as follows:</p>
1295
+ %QUESTIONS_ANSWERS%";
1296
+ update_option( 'qmn-settings' , $settings );
1297
  }
1298
+
 
 
1299
  update_option('mlw_quiz_master_version' , $data);
 
 
 
 
1300
  }
1301
  if ( ! get_option('mlw_advert_shows') ) {
1302
  add_option( 'mlw_advert_shows' , 'true' );
1324
  if ( $file == QSM_PLUGIN_BASENAME ) {
1325
  $row_meta = array(
1326
  'docs' => '<a href="' . esc_url( 'https://docs.quizandsurveymaster.com/' ) . '" title="' . esc_attr( __( 'View Documentation', 'quiz-master-next' ) ) . '">' . __( 'Documentation', 'quiz-master-next' ) . '</a>',
1327
+ 'support' => '<a href="' . admin_url( 'admin.php?page=qsm_quiz_help' ) . '" title="' . esc_attr( __( 'Create Support Ticket', 'quiz-master-next' ) ) . '">' . __( 'Support', 'quiz-master-next' ) . '</a>',
1328
  );
1329
  return array_merge( $links, $row_meta );
1330
  }
php/classes/class-qsm-results-pages.php ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Handles relevant functions for results pages
4
+ *
5
+ * @package QSM
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ /**
13
+ * This class contains functions for loading, saving, and generating results pages.
14
+ *
15
+ * @since 6.2.0
16
+ */
17
+ class QSM_Results_Pages {
18
+
19
+ /**
20
+ * Creates the HTML for the results page.
21
+ *
22
+ * @since 6.2.0
23
+ * @param array $response_data The data for the user's submission.
24
+ * @return string The HTML for the page to be displayed.
25
+ */
26
+ public static function generate_pages( $response_data ) {
27
+ $pages = QSM_Results_Pages::load_pages( $response_data['quiz_id'] );
28
+ $default = '%QUESTIONS_ANSWERS%';
29
+ $redirect = false;
30
+ $default_redirect = false;
31
+ ob_start();
32
+ ?>
33
+ <div class="qsm-results-page">
34
+ <?php
35
+ do_action( 'qsm_before_results_page' );
36
+
37
+ // Cycles through each possible page.
38
+ foreach ( $pages as $page ) {
39
+
40
+ // Checks if any conditions are present. Else, set it as the default.
41
+ if ( ! empty( $page['conditions'] ) ) {
42
+ /**
43
+ * Since we have many conditions to test, we set this to true first.
44
+ * Then, we test each condition to see if it fails.
45
+ * If one condition fails, the value will be set to false.
46
+ * If all conditions pass, this will still be true and the page will
47
+ * be shown.
48
+ */
49
+ $show = true;
50
+
51
+ // Cycle through each condition to see if we should show this page.
52
+ foreach ( $page['conditions'] as $condition ) {
53
+ $value = $condition['value'];
54
+
55
+ // First, determine which value we need to test.
56
+ switch ( $condition['criteria'] ) {
57
+ case 'score':
58
+ $test = $response_data['total_score'];
59
+ break;
60
+
61
+ case 'points':
62
+ $test = $response_data['total_points'];
63
+ break;
64
+
65
+ default:
66
+ $test = 0;
67
+ break;
68
+ }
69
+
70
+ // Then, determine how to test the vaue.
71
+ switch ( $condition['operator'] ) {
72
+ case 'greater-equal':
73
+ if ( $test < $value ) {
74
+ $show = false;
75
+ }
76
+ break;
77
+
78
+ case 'greater':
79
+ if ( $test <= $value ) {
80
+ $show = false;
81
+ }
82
+ break;
83
+
84
+ case 'less-equal':
85
+ if ( $test > $value ) {
86
+ $show = false;
87
+ }
88
+ break;
89
+
90
+ case 'less':
91
+ if ( $test >= $value ) {
92
+ $show = false;
93
+ }
94
+ break;
95
+
96
+ case 'not-equal':
97
+ if ( $test == $value ) {
98
+ $show = false;
99
+ }
100
+ break;
101
+
102
+ case 'equal':
103
+ default:
104
+ if ( $test != $value ) {
105
+ $show = false;
106
+ }
107
+ break;
108
+ }
109
+
110
+ /**
111
+ * Added custom criterias/operators to the results pages?
112
+ * Use this filter to check if the condition passed.
113
+ * If it fails your conditions, return false to prevent the
114
+ * page from showing.
115
+ * If it passes your condition or is not your custom criterias
116
+ * or operators, then return the value as-is.
117
+ * DO NOT RETURN TRUE IF IT PASSES THE CONDITION!!!
118
+ * The value may have been set to false when failing a previous condition.
119
+ */
120
+ $show = apply_filters( 'qsm_results_page_condition_check', $show, $condition, $response_data );
121
+ }
122
+
123
+ // If we passed all conditions, show this page.
124
+ if ( $show ) {
125
+ $content = $page['page'];
126
+ if ( $page['redirect'] ) {
127
+ $redirect = $page['redirect'];
128
+ }
129
+ }
130
+ } else {
131
+ $default = $page['page'];
132
+ if ( $page['redirect'] ) {
133
+ $default_redirect = $page['redirect'];
134
+ }
135
+ }
136
+ }
137
+
138
+ // If no page was set to the content, set to the page that was a default page.
139
+ if ( empty( $content ) ) {
140
+ $content = $default;
141
+ }
142
+
143
+ // If no redirect was set, set to default redirect.
144
+ if ( ! $redirect ) {
145
+ $redirect = $default_redirect;
146
+ }
147
+
148
+ // Decodes special characters, runs through our template
149
+ // variables, and then outputs the text.
150
+ $page = htmlspecialchars_decode( $content, ENT_QUOTES );
151
+ $page = apply_filters( 'mlw_qmn_template_variable_results_page', $page, $response_data );
152
+ echo str_replace( "\n", '<br>', $page );
153
+ do_action( 'qsm_after_results_page' );
154
+ ?>
155
+ </div>
156
+ <?php
157
+ return array(
158
+ 'display' => do_shortcode( ob_get_clean() ),
159
+ 'redirect' => $redirect,
160
+ );
161
+ }
162
+
163
+ /**
164
+ * Loads the results pages for a single quiz.
165
+ *
166
+ * @since 6.2.0
167
+ * @param int $quiz_id The ID for the quiz.
168
+ * @return bool|array The array of pages or false.
169
+ */
170
+ public static function load_pages( $quiz_id ) {
171
+ $pages = array();
172
+ $quiz_id = intval( $quiz_id );
173
+
174
+ // If the parameter supplied turns to 0 after intval, returns false.
175
+ if ( 0 === $quiz_id ) {
176
+ return false;
177
+ }
178
+
179
+ global $wpdb;
180
+ $results = $wpdb->get_var( $wpdb->prepare( "SELECT message_after FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ) );
181
+
182
+ // Checks if the results is an array.
183
+ if ( is_serialized( $results ) && is_array( maybe_unserialize( $results ) ) ) {
184
+ $results = maybe_unserialize( $results );
185
+
186
+ // Checks if the results array is not the newer version.
187
+ if ( ! empty( $results ) && ! isset( $results[0]['conditions'] ) ) {
188
+ $pages = QSM_Results_Pages::convert_to_new_system( $quiz_id );
189
+ } else {
190
+ $pages = $results;
191
+ }
192
+ } else {
193
+ $pages = QSM_Results_Pages::convert_to_new_system( $quiz_id );
194
+ }
195
+
196
+ return $pages;
197
+ }
198
+
199
+ /**
200
+ * Loads and converts results pages from the old system to new system
201
+ *
202
+ * @since 6.2.0
203
+ * @param int $quiz_id The ID for the quiz.
204
+ * @return array The combined newer versions of the pages.
205
+ */
206
+ public static function convert_to_new_system( $quiz_id ) {
207
+ $pages = array();
208
+ $quiz_id = intval( $quiz_id );
209
+
210
+ // If the parameter supplied turns to 0 after intval, returns empty array.
211
+ if ( 0 === $quiz_id ) {
212
+ return $pages;
213
+ }
214
+
215
+ /**
216
+ * Loads the old results pages and converts them.
217
+ */
218
+ global $wpdb;
219
+ global $mlwQuizMasterNext;
220
+ $data = $wpdb->get_row( $wpdb->prepare( "SELECT message_after FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ), ARRAY_A );
221
+ $system = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'system', 0 );
222
+ $old_pages = maybe_unserialize( $data['message_after'] );
223
+
224
+ // If the value is an array, convert it.
225
+ // If not, use it as the contents of the results page.
226
+ if ( is_array( $old_pages ) ) {
227
+
228
+ // Cycle through the older version of results pages.
229
+ foreach ( $old_pages as $page ) {
230
+ $new_page = array(
231
+ 'conditions' => array(),
232
+ 'page' => $page[2],
233
+ 'redirect' => false,
234
+ );
235
+
236
+ // If the page used the older version of the redirect, add it.
237
+ if ( ! empty( $page['redirect_url'] ) ) {
238
+ $new_page['redirect'] = $page['redirect_url'];
239
+ }
240
+
241
+ // Checks to see if the page is not the older version's default page.
242
+ if ( 0 !== intval( $page[0] ) || 0 !== intval( $page[1] ) ) {
243
+
244
+ // Checks if the system is points.
245
+ if ( 1 === intval( $system ) ) {
246
+ $new_page['conditions'][] = array(
247
+ 'criteria' => 'points',
248
+ 'operator' => 'greater-equal',
249
+ 'value' => $page[0],
250
+ );
251
+ $new_page['conditions'][] = array(
252
+ 'criteria' => 'points',
253
+ 'operator' => 'less-equal',
254
+ 'value' => $page[1],
255
+ );
256
+ } else {
257
+ $new_page['conditions'][] = array(
258
+ 'criteria' => 'score',
259
+ 'operator' => 'greater-equal',
260
+ 'value' => $page[0],
261
+ );
262
+ $new_page['conditions'][] = array(
263
+ 'criteria' => 'score',
264
+ 'operator' => 'less-equal',
265
+ 'value' => $page[1],
266
+ );
267
+ }
268
+ }
269
+
270
+ $pages[] = $new_page;
271
+ }
272
+ } else {
273
+ $pages[] = array(
274
+ 'conditions' => array(),
275
+ 'page' => $old_pages,
276
+ 'redirect' => false,
277
+ );
278
+ }
279
+
280
+ // Updates the database with new array to prevent running this step next time.
281
+ $wpdb->update(
282
+ $wpdb->prefix . 'mlw_quizzes',
283
+ array( 'message_after' => serialize( $pages ) ),
284
+ array( 'quiz_id' => $quiz_id ),
285
+ array( '%s' ),
286
+ array( '%d' )
287
+ );
288
+
289
+ return $pages;
290
+ }
291
+
292
+ /**
293
+ * Saves the results pages for a quiz.
294
+ *
295
+ * @since 6.2.0
296
+ * @param int $quiz_id The ID for the quiz.
297
+ * @param array $pages The results pages to be saved.
298
+ * @return bool True or false depending on success.
299
+ */
300
+ public static function save_pages( $quiz_id, $pages ) {
301
+ if ( ! is_array( $pages ) ) {
302
+ return false;
303
+ }
304
+
305
+ $quiz_id = intval( $quiz_id );
306
+ if ( 0 === $quiz_id ) {
307
+ return false;
308
+ }
309
+
310
+ // Sanitizes data in pages.
311
+ $total = count( $pages );
312
+ for ( $i = 0; $i < $total; $i++ ) {
313
+
314
+ // jQuery AJAX will send a string version of false.
315
+ if ( 'false' === $pages[ $i ]['redirect'] ) {
316
+ $pages[ $i ]['redirect'] = false;
317
+ }
318
+
319
+ /**
320
+ * The jQuery AJAX function won't send the conditions key
321
+ * if it's empty. So, check if it's set. If set, sanitize
322
+ * data. If not set, set to empty array.
323
+ */
324
+ if ( isset( $pages[ $i ]['conditions'] ) ) {
325
+ // Sanitizes the conditions.
326
+ $total_conditions = count( $pages[ $i ]['conditions'] );
327
+ for ( $j = 0; $j < $total_conditions; $j++ ) {
328
+ $pages[ $i ]['conditions'][ $j ]['value'] = sanitize_text_field( $pages[ $i ]['conditions'][ $j ]['value'] );
329
+ }
330
+ } else {
331
+ $pages[ $i ]['conditions'] = array();
332
+ }
333
+ }
334
+
335
+ global $wpdb;
336
+ $results = $wpdb->update(
337
+ $wpdb->prefix . 'mlw_quizzes',
338
+ array( 'message_after' => serialize( $pages ) ),
339
+ array( 'quiz_id' => $quiz_id ),
340
+ array( '%s' ),
341
+ array( '%d' )
342
+ );
343
+ if ( false !== $results ) {
344
+ return true;
345
+ } else {
346
+ return false;
347
+ }
348
+ }
349
+ }
350
+ ?>
php/classes/class-qsm-settings.php CHANGED
@@ -244,15 +244,11 @@ class QSM_Quiz_Settings {
244
  */
245
  private function load_settings() {
246
 
247
- global $wpdb;
248
  $settings_array = array();
249
 
250
  // Loads the settings from the database
251
  $settings = $wpdb->get_var( $wpdb->prepare( "SELECT quiz_settings FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d", $this->quiz_id ) );
252
-
253
- if ( is_null( $settings ) ) {
254
- return;
255
- }
256
 
257
  // Unserializes array
258
  if ( is_serialized( $settings ) && is_array( @unserialize( $settings ) ) ) {
@@ -401,23 +397,38 @@ class QSM_Quiz_Settings {
401
  $this->settings = $settings_array;
402
  }
403
 
404
- /**
405
- * Loads the old object model of options for backwards compatibility
406
- *
407
- * @since 5.0.0
408
- */
409
- public function get_quiz_options() {
410
- global $wpdb;
411
 
412
- // Load the old options system
413
- $quiz_options = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $this->quiz_id ) );
414
 
415
- // Merge all settings into old object
416
- $quiz_override = array_merge( (array) $quiz_options, $this->get_setting( 'quiz_leaderboards' ), $this->get_setting( 'quiz_options' ), $this->get_setting( 'quiz_text' ) );
 
 
 
 
 
417
 
418
- // Return as old object model
419
- return (object) $quiz_override;
420
- }
 
 
 
 
 
 
 
 
 
 
421
  }
422
 
423
  ?>
244
  */
245
  private function load_settings() {
246
 
247
+ global $wpdb;
248
  $settings_array = array();
249
 
250
  // Loads the settings from the database
251
  $settings = $wpdb->get_var( $wpdb->prepare( "SELECT quiz_settings FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d", $this->quiz_id ) );
 
 
 
 
252
 
253
  // Unserializes array
254
  if ( is_serialized( $settings ) && is_array( @unserialize( $settings ) ) ) {
397
  $this->settings = $settings_array;
398
  }
399
 
400
+ /**
401
+ * Loads the old object model of options for backwards compatibility
402
+ *
403
+ * @since 5.0.0
404
+ */
405
+ public function get_quiz_options() {
406
+ global $wpdb;
407
 
408
+ // Load the old options system
409
+ $quiz_options = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $this->quiz_id ), ARRAY_A );
410
 
411
+ /**
412
+ * Merges all options and settings
413
+ */
414
+ $leaderboards = $this->get_setting( 'quiz_leaderboards' );
415
+ if ( is_array( $leaderboards ) ) {
416
+ $quiz_options = array_merge( $quiz_options, $leaderboards );
417
+ }
418
 
419
+ $options = $this->get_setting( 'quiz_options' );
420
+ if ( is_array( $options ) ) {
421
+ $quiz_options = array_merge( $quiz_options, $options );
422
+ }
423
+
424
+ $text = $this->get_setting( 'quiz_text' );
425
+ if ( is_array( $text ) ) {
426
+ $quiz_options = array_merge( $quiz_options, $text );
427
+ }
428
+
429
+ // Return as old object model
430
+ return (object) $quiz_options;
431
+ }
432
  }
433
 
434
  ?>
php/rest-api.php CHANGED
@@ -30,6 +30,126 @@ function qsm_register_rest_routes() {
30
  'methods' => WP_REST_Server::READABLE,
31
  'callback' => 'qsm_rest_get_question',
32
  ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
34
 
35
  /**
30
  'methods' => WP_REST_Server::READABLE,
31
  'callback' => 'qsm_rest_get_question',
32
  ) );
33
+ register_rest_route( 'quiz-survey-master/v1', '/quizzes/(?P<id>\d+)/results', array(
34
+ 'methods' => WP_REST_Server::READABLE,
35
+ 'callback' => 'qsm_rest_get_results',
36
+ ) );
37
+ register_rest_route( 'quiz-survey-master/v1', '/quizzes/(?P<id>\d+)/results', array(
38
+ 'methods' => WP_REST_Server::EDITABLE,
39
+ 'callback' => 'qsm_rest_save_results',
40
+ ) );
41
+ register_rest_route( 'quiz-survey-master/v1', '/quizzes/(?P<id>\d+)/emails', array(
42
+ 'methods' => WP_REST_Server::READABLE,
43
+ 'callback' => 'qsm_rest_get_emails',
44
+ ) );
45
+ register_rest_route( 'quiz-survey-master/v1', '/quizzes/(?P<id>\d+)/emails', array(
46
+ 'methods' => WP_REST_Server::EDITABLE,
47
+ 'callback' => 'qsm_rest_save_emails',
48
+ ) );
49
+ }
50
+
51
+ /**
52
+ * Gets emails for a quiz.
53
+ *
54
+ * @since 6.2.0
55
+ * @param WP_REST_Request $request The request sent from WP REST API.
56
+ * @return array The emails for the quiz.
57
+ */
58
+ function qsm_rest_get_emails( WP_REST_Request $request ) {
59
+ // Makes sure user is logged in.
60
+ if ( is_user_logged_in() ) {
61
+ $current_user = wp_get_current_user();
62
+ if ( 0 !== $current_user ) {
63
+ $emails = QSM_Emails::load_emails( $request['id'] );
64
+ if ( false === $emails || ! is_array( $emails ) ) {
65
+ $emails = array();
66
+ }
67
+ return $emails;
68
+ }
69
+ }
70
+ return array(
71
+ 'status' => 'error',
72
+ 'msg' => 'User not logged in',
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Saves emails for a quiz.
78
+ *
79
+ * @since 6.2.0
80
+ * @param WP_REST_Request $request The request sent from WP REST API.
81
+ * @return array The status of saving the emails.
82
+ */
83
+ function qsm_rest_save_emails( WP_REST_Request $request ) {
84
+ // Makes sure user is logged in.
85
+ if ( is_user_logged_in() ) {
86
+ $current_user = wp_get_current_user();
87
+ if ( 0 !== $current_user ) {
88
+ if ( ! isset( $request['emails'] ) || ! is_array( $request['emails'] ) ) {
89
+ $request['emails'] = array();
90
+ }
91
+ $result = QSM_Emails::save_emails( $request['id'], $request['emails'] );
92
+ return array(
93
+ 'status' => $result,
94
+ );
95
+ }
96
+ }
97
+ return array(
98
+ 'status' => 'error',
99
+ 'msg' => 'User not logged in',
100
+ );
101
+ }
102
+
103
+ /**
104
+ * Gets results pages for a quiz.
105
+ *
106
+ * @since 6.2.0
107
+ * @param WP_REST_Request $request The request sent from WP REST API.
108
+ * @return array The pages for the quiz.
109
+ */
110
+ function qsm_rest_get_results( WP_REST_Request $request ) {
111
+ // Makes sure user is logged in.
112
+ if ( is_user_logged_in() ) {
113
+ $current_user = wp_get_current_user();
114
+ if ( 0 !== $current_user ) {
115
+ $pages = QSM_Results_Pages::load_pages( $request['id'] );
116
+ if ( false === $pages || ! is_array( $pages ) ) {
117
+ $pages = array();
118
+ }
119
+ return $pages;
120
+ }
121
+ }
122
+ return array(
123
+ 'status' => 'error',
124
+ 'msg' => 'User not logged in',
125
+ );
126
+ }
127
+
128
+ /**
129
+ * Gets results pages for a quiz.
130
+ *
131
+ * @since 6.2.0
132
+ * @param WP_REST_Request $request The request sent from WP REST API.
133
+ * @return array The results from saving the pages.
134
+ */
135
+ function qsm_rest_save_results( WP_REST_Request $request ) {
136
+ // Makes sure user is logged in.
137
+ if ( is_user_logged_in() ) {
138
+ $current_user = wp_get_current_user();
139
+ if ( 0 !== $current_user ) {
140
+ if ( ! isset( $request['pages'] ) || ! is_array( $request['pages'] ) ) {
141
+ $request['pages'] = array();
142
+ }
143
+ $result = QSM_Results_Pages::save_pages( $request['id'], $request['pages'] );
144
+ return array(
145
+ 'status' => $result,
146
+ );
147
+ }
148
+ }
149
+ return array(
150
+ 'status' => 'error',
151
+ 'msg' => 'User not logged in',
152
+ );
153
  }
154
 
155
  /**
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: quiz, survey, lead, test, score, exam, questionnaire, question
4
  Requires at least: 4.9
5
  Tested up to: 5.0.2
6
  Requires PHP: 5.4
7
- Stable tag: 6.1.2
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -111,6 +111,14 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
111
 
112
  == Changelog ==
113
 
 
 
 
 
 
 
 
 
114
  = 6.1.2 (January 7, 2019) =
115
  * Closed User Request: Add special character selector to question editor ([Issue #750](https://github.com/fpcorso/quiz_master_next/issues/750))
116
  * Closed User Request: Add total questions and total pages to Questions tab ([Issue #749](https://github.com/fpcorso/quiz_master_next/issues/749))
@@ -123,29 +131,6 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
123
  * Adds new Gutenberg blocks
124
  * Fixes undefined access at delete_question static function (Thanks [bpanatta](https://github.com/fpcorso/quiz_master_next/pull/746)!
125
 
126
- = 6.0.4 (October 2, 2018) =
127
- * Changes links from old documentation to newer documentation
128
-
129
- = 6.0.3 (August 20, 2018) =
130
- * Closed Bug: User gets 'trapped' if timer runs out on required question when questions are paginated ([Issue #583](https://github.com/fpcorso/quiz_master_next/issues/583))
131
- * Closed Bug: If user refreshes quiz page when timer is at 0, cannot submit ([Issue #501](https://github.com/fpcorso/quiz_master_next/issues/501))
132
- * Closed Bug: Saving quiz name when editing results in error if no changes are made ([Issue #391](https://github.com/fpcorso/quiz_master_next/issues/391))
133
- * Adds deprecated notice to the quiz setting functions found in the quizCreator object
134
- * Adds hook after results are stored in the database
135
-
136
- = 6.0.2 (July 18, 2018) =
137
- * Closed Bug: PHP warning thrown on Help page ([Issue #711](https://github.com/fpcorso/quiz_master_next/issues/711))
138
- * Closed Bug: Timer not working on certain sites when using questions per page option ([Issue #709](https://github.com/fpcorso/quiz_master_next/issues/709))
139
- * Closed Bug: Blank page shown when contact fields and message fields are empty ([Issue #707](https://github.com/fpcorso/quiz_master_next/issues/707))
140
-
141
- = 6.0.1 (July 11, 2018) =
142
- * Closed Bug: Quiz comment box shows HTML in label when using newer pagination system ([Issue #704](https://github.com/fpcorso/quiz_master_next/issues/704))
143
-
144
- = 6.0.0 (June 20, 2018) =
145
- * Closed Enhancement: Remove Tools tab ([Issue #689](https://github.com/fpcorso/quiz_master_next/issues/689))
146
- * Closed Enhancement: Bump Minimum PHP Version To 5.4 ([Issue #607](https://github.com/fpcorso/quiz_master_next/issues/607))
147
- * Closed Enhancement: Move Leaderboards to free addon ([Issue #380](https://github.com/fpcorso/quiz_master_next/issues/380))
148
-
149
  ([Read Full Changelog](https://github.com/fpcorso/quiz_master_next/blob/master/CHANGELOG.md))
150
 
151
  == Upgrade Notice ==
4
  Requires at least: 4.9
5
  Tested up to: 5.0.2
6
  Requires PHP: 5.4
7
+ Stable tag: 6.2.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
111
 
112
  == Changelog ==
113
 
114
+ = 6.2.0 (January 31, 2019) =
115
+ * Closed Enhancement: Create new alert system on quiz options page ([Issue #754](https://github.com/fpcorso/quiz_master_next/issues/754))
116
+ * Closed Bug: No access allowed when clicking "Support" from plugins page ([Issue #753](https://github.com/fpcorso/quiz_master_next/issues/753))
117
+ * Closed Bug: To many redirects ([Issue #745](https://github.com/fpcorso/quiz_master_next/issues/745))
118
+ * Closed User Request: Allow default email to be deleted or turned off ([Issue #735](https://github.com/fpcorso/quiz_master_next/issues/735))
119
+ * Closed Enhancement: Rewrite emails to allow for different conditions ([Issue #379](https://github.com/fpcorso/quiz_master_next/issues/379))
120
+ * Closed Enhancement: Rewrite results pages to allow for different conditions ([Issue #378](https://github.com/fpcorso/quiz_master_next/issues/378))
121
+
122
  = 6.1.2 (January 7, 2019) =
123
  * Closed User Request: Add special character selector to question editor ([Issue #750](https://github.com/fpcorso/quiz_master_next/issues/750))
124
  * Closed User Request: Add total questions and total pages to Questions tab ([Issue #749](https://github.com/fpcorso/quiz_master_next/issues/749))
131
  * Adds new Gutenberg blocks
132
  * Fixes undefined access at delete_question static function (Thanks [bpanatta](https://github.com/fpcorso/quiz_master_next/pull/746)!
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  ([Read Full Changelog](https://github.com/fpcorso/quiz_master_next/blob/master/CHANGELOG.md))
135
 
136
  == Upgrade Notice ==