Skip to content

Commit

Permalink
Merge pull request #2477 from QuizandSurveyMaster/CU-86cu78701-restap…
Browse files Browse the repository at this point in the history
…i-for-quiz-result-submitquiz

Cu 86cu78701 restapi for quiz result submitquiz
  • Loading branch information
zubairraeen authored Mar 8, 2024
2 parents 570c42f + aca9966 commit 9a9b496
Show file tree
Hide file tree
Showing 8 changed files with 690 additions and 18 deletions.
7 changes: 6 additions & 1 deletion css/qsm-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,11 @@ input#preferred-date-format-custom {
color: #ca1010; border-color: #ca1010;
}


.qsm-api-keys-options .qsm-api-keys-option {
margin: 0 0 10px 0;
}

/*TinyMCE Text-editor : start */
.mce-container .qsm-autocomplete {
position: absolute !important;
Expand Down Expand Up @@ -3402,4 +3407,4 @@ input#preferred-date-format-custom {
color: #ffffff;
padding: 0px 7px;
}
/*TinyMCE Text-editor : end */
/*TinyMCE Text-editor : end */
22 changes: 22 additions & 0 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3883,6 +3883,27 @@ var import_button;
});
}
}

$(document).on('click', '.qsm-api-settings-form .qsm-generate-api-key', function (event) {
event.preventDefault();
if (!$(this).hasClass('confirmation') || confirm(qsm_api_object.confirmation_message)) {
$.ajax({
type: "POST",
url: ajaxurl,
data: {
action: 'regenerate_api_key',
nonce: qsm_api_object.nonce
},
success: function (response) {
$("#qsm_api_key").val(response.data);
},
error: function (xhr, status, error) {
alert("Error: " + error);
}
});
}
});

jQuery(document).on('click', '.qsm-mark-as-default', function () {
jQuery('.qsm-mark-as-default').not(jQuery(this)).prop('checked', false);
})
Expand Down Expand Up @@ -3932,4 +3953,5 @@ var import_button;
qsmHandleOperatorChange('results-page-condition', 'condition-default-value');
qsmHandleConditionChange('email-condition', 'email-extra-condition-category', 'email-condition-operator', 'email-condition-criteria', 'condition-default-value');
qsmHandleOperatorChange('email-condition', 'condition-default-value');

}(jQuery));
10 changes: 10 additions & 0 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ class MLWQuizMasterNext {
*/
public $check_license;

/**
* Holds quiz_data
*
* @var object
* @since 7.3.8
*/
public $qsm_api;

/**
* Holds quiz_data
*
Expand Down Expand Up @@ -232,6 +240,8 @@ private function load_dependencies() {


include_once 'php/rest-api.php';
include_once 'php/classes/class-qsm-quiz-api.php';
$this->qsm_api = new QSMQuizApi();
}

/**
Expand Down
39 changes: 35 additions & 4 deletions php/admin/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,38 @@ public function ip_collection_field() {
*/
public static function display_page() {
global $mlwQuizMasterNext;

$active_tab = 'qmn_global_settings';
if ( isset( $_GET['tab'] ) ) {
if ( sanitize_text_field( wp_unslash( $_GET['tab'] ) ) == 'qmn_global_settings' ) {
$active_tab = 'qmn_global_settings';
} elseif ( sanitize_text_field( wp_unslash( $_GET['tab'] ) ) == 'qsm_api_settings' ) {
$active_tab = 'qsm_api_settings';
} else {
$active_tab = 'quiz-default-options';
}
}
$api_tab_class = '';
if ( 'qsm_api_settings' === $active_tab ) {
$api_tab_class = 'nav-tab-active';
}
?>
<div class="wrap">
<h2><?php esc_html_e( 'Global Settings', 'quiz-master-next' ); ?></h2>
<h2 class="nav-tab-wrapper">
<!-- when tab buttons are clicked we jump back to the same page but with a new parameter that represents the clicked tab. accordingly we make it active -->
<a href="?page=qmn_global_settings&tab=qmn_global_settings" class="nav-tab <?php echo empty( $_GET['tab'] ) || 'qmn_global_settings' === $_GET['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Main Settings', 'quiz-master-next' ); ?></a>
<a href="?page=qmn_global_settings&tab=quiz-default-options" class="nav-tab <?php echo ! empty( $_GET['tab'] ) && 'quiz-default-options' === $_GET['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Quiz Default Options', 'quiz-master-next' ); ?></a>
<a href="?page=qmn_global_settings&tab=quiz-apply-default-options" class="nav-tab <?php echo ! empty( $_GET['tab'] ) && 'quiz-apply-default-options' === $_GET['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Apply Default Options', 'quiz-master-next' ); ?></a>
<a href="?page=qmn_global_settings&tab=qsm_api_settings" class="nav-tab <?php echo esc_attr( $api_tab_class ); ?>"><?php esc_html_e( 'Quiz Api Options', 'quiz-master-next' ); ?></a>
</h2>
<?php
if ( 'qsm_api_settings' === $active_tab ) {
$mlwQuizMasterNext->qsm_api->load_form_field();
} ?>

<?php if ( empty( $_GET['tab'] ) || 'qmn_global_settings' === $_GET['tab'] || 'quiz-default-options' === $_GET['tab'] ) { ?>

<form action="options.php" method="POST" class="qsm_global_settings">
<?php
if ( isset( $_GET['settings-updated'] ) ) {
Expand All @@ -552,6 +574,7 @@ public static function display_page() {
echo '<span>' . esc_html__( ' Settings have been updated!', 'quiz-master-next' ) . '</span>';
echo '</div>';
}

if ( empty( $_GET['tab'] ) || 'qmn_global_settings' === $_GET['tab'] ) {
settings_fields( 'qmn-settings-group' );
do_settings_sections( 'qmn_global_settings' );
Expand All @@ -561,10 +584,18 @@ public static function display_page() {
?>
<div class="qsm-sub-tab-menu" style="display: inline-block;width: 100%;">
<ul class="subsubsub">
<li><a href="javascript:void(0)" data-id="qsm_general" class="current quiz_style_tab"><?php esc_html_e( 'General', 'quiz-master-next' ); ?></a></li>
<li><a href="javascript:void(0)" data-id="quiz_submission" class="quiz_style_tab"><?php esc_html_e( 'Quiz submission', 'quiz-master-next' ); ?></a></li>
<li><a href="javascript:void(0)" data-id="display" class="quiz_style_tab"><?php esc_html_e( 'Display', 'quiz-master-next' ); ?></a></li>
<li><a href="javascript:void(0)" data-id="contact_form" class="quiz_style_tab"><?php esc_html_e( 'Contact form', 'quiz-master-next' ); ?></a></li>
<li>
<a href="javascript:void(0)" data-id="qsm_general" class="current quiz_style_tab"><?php esc_html_e( 'General', 'quiz-master-next' ); ?></a>
</li>
<li>
<a href="javascript:void(0)" data-id="quiz_submission" class="quiz_style_tab"><?php esc_html_e( 'Quiz submission', 'quiz-master-next' ); ?></a>
</li>
<li>
<a href="javascript:void(0)" data-id="display" class="quiz_style_tab"><?php esc_html_e( 'Display', 'quiz-master-next' ); ?></a>
</li>
<li>
<a href="javascript:void(0)" data-id="contact_form" class="quiz_style_tab"><?php esc_html_e( 'Contact form', 'quiz-master-next' ); ?></a>
</li>
</ul>
</div>

Expand Down
8 changes: 4 additions & 4 deletions php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class QMNQuizManager {
public $mathjax_url = QSM_PLUGIN_JS_URL . '/mathjax/tex-mml-chtml.js';
public $mathjax_version = '3.2.0';

protected $qsm_background_email;
public $qsm_background_email;
/**
* Main Construct Function
*
Expand Down Expand Up @@ -1738,13 +1738,13 @@ public function submit_results( $qmn_quiz_options, $qmn_array_for_variables ) {
if ( 'name' === $field['use'] ) {
$qmn_array_for_variables['user_name'] = $field['value'];
}
if ( 'comp' === $field['use'] ) {
elseif ( 'comp' === $field['use'] ) {
$qmn_array_for_variables['user_business'] = $field['value'];
}
if ( 'email' === $field['use'] ) {
elseif ( 'email' === $field['use'] ) {
$qmn_array_for_variables['user_email'] = $field['value'];
}
if ( 'phone' === $field['use'] ) {
elseif ( 'phone' === $field['use'] ) {
$qmn_array_for_variables['user_phone'] = $field['value'];
}
}
Expand Down
Loading

0 comments on commit 9a9b496

Please sign in to comment.